DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find if a user is admin

Sometimes, a script might need to know if a user has admin access on the local computer.  Rather than throw an error, I wanted to find a way to determine if the user has admin access. I found the below script, and hopefully, others here will find it useful.  This works well as an admin, I have not tested it as a standard user. 

 

http://stackoverflow.com/questions/301860/best-way-to-know-if-a-user-has-administrative-privileges-f...

 

Dim objNetwork, strComputer, strUser
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strUser = objNetwork.UserName
msgbox(strComputer)

dim isAdministrator
isAdministrator = false
Dim objGroup, objUser
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")

For Each objUser in objGroup.Members
    If objUser.Name = strUser Then
        isAdministrator = true        
    End If
Next

If isAdministrator Then
    Msgbox(strUser & " is a local administrator.")
Else
    Msgbox(strUser & " is not a local administrator.")
End If

 

0 Kudos
Message 1 of 1
(2,971 Views)