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
This article has a nice chunk of code on how to enumerate the members of a group (copied here for convenience and edited to not use email address):
Function RetrieveUsers(domainName,grpName)
dim GrpObj
dim mbrlist
dim mbr
'-------------------------------------------------------------------------------
' *** Enumerate Group Members ***
'-------------------------------------------------------------------------------
' Build the ADSI query and retrieve the group object
Set GrpObj = GetObject("WinNT://" & domainName & "/" & grpName & ",group")
' Loop through the group membership and build a string containing the names
for each mbr in GrpObj.Members
mbrlist = mbrlist & vbTab & mbr.name & vbCrLf
Next
RetrieveUsers=mbrlist
End Function
You can then write a function to see if a user is in the list...
Function IsAdmin(user)
IsAdmin = InStr(RetrieveUsers("MachineName", "Administrators"), user) > 0
End Function
...and call it like this:
If IsAdmin("LocalAccount") Then
Wscript.Echo "LocalAccount is an admin"
Else
Wscript.Echo "LocalAccount is not an admin"
End If