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
Using "localhost" instead of the real hostname increases the script runtime about 10x!
My final code is:
' get_admin_status.vbs
Option Explicit
Dim oGroup: Set oGroup = GetObject("WinNT://localhost/Administrators,group")
Dim oNetwork: Set oNetwork = CreateObject("Wscript.Network")
Dim sSearchPattern: sSearchPattern = "WinNT://" & oNetwork.UserDomain & "/" & oNetwork.UserName
Dim sMember
For Each sMember In oGroup.Members
If sMember.adsPath = sSearchPattern Then
' Found...
Call WScript.Quit(0)
End If
Next
' Not found...
Call WScript.Quit(1)
This script returns exit code 0 if the current user is a local admin.
Usage: cscript.exe get_admin_status.vbs