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
User may be not in local administrator group. For example - domain admins. UAC usually blocks admin access to registry, shares e.t.c. even for administrators(onl y manual "run as admin" gets right)...
Here is my crazy way:
Set Shell = CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
strCheckFolder = Shell.ExpandEnvironmentStrings("%USERPROFILE%")
strCheckFolder = strCheckFolder+"\TempFolder"
if fso.FolderExists(strCheckFolder) then
fso.DeleteFolder(strCheckFolder)
end if
fso.CreateFolder(strCheckFolder)
tempstr = "cmd.exe /u /c chcp 65001 | whoami /all >" & strCheckFolder & "\rights.txt"
Shell.run tempstr
tempstr = strCheckFolder & "\rights.txt"
WScript.Sleep 200
Set txtFile = FSO.OpenTextFile(tempstr,1)
IsAdmin = False
Do While Not txtFile.AtEndOfStream
x=txtFile.Readline
If InStr(x, "S-1-5-32-544") Then
IsAdmin = True
End If
Loop
txtFile.Close