Best way to know if a user has administrative privileges from a VBScript

后端 未结 10 1916
不知归路
不知归路 2021-01-02 21:50

I need to check whether the user executing the script has administrative privileges on the machine.

I have specified the user executing the script because the script

10条回答
  •  离开以前
    2021-01-02 22:11

    What about checking for "\\computername\Admin$\system32"?

    function IsLoggedInAsAdmin()
        isAdmin = false
        set shell = CreateObject("WScript.Shell")
        computername = WshShell.ExpandEnvironmentStrings("%computername%")
        strAdmin = "\\" & computername & "\Admin$\System32"
    
        isAdmin = false
    
        set fso = CreateObject("Scripting.FileSystemObject")
    
        if fso.FolderExists(strAdmin) then
            isAdmin = true
        end if
    
        IsLoggedInAsAdmin = isAdmin
    end function
    

提交回复
热议问题