WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check if You Have Local Admin Rights

 Keywords: Local Admin Administrator Rights  

When in a domain, you can have local admin rights by either being in the local administrators group or being in a global domain group that is included in the local administrators group.

Here's how to check

Mypath = StrLower(DirScript())
MyPC = StrLower(Environment("Computername"))
Myuser = StrLower(Environment("Username"))
MyLogonServer = StrLower(Environment("LogonServer"))
AddExtender("WWWNT34i.DLL")

;----------------------------------------------------------------------------------
; See if user has direct admin rights

ErrMode = ErrorMode(@OFF)
localpriv = StrLower(wntUserProps("",MyUser,7,0))
ErrorMode(ErrMode)
Admin = localpriv=="admin"

;----------------------------------------------------------------------------------
; If no direct admin rights and domain login, see if user has indirect admin rights

If !Admin && MyLogonServer!=MyPC
   ErrMode = ErrorMode(@OFF)
   glist = StrLower(wntMemberGrps(MyLogonServer,MyUser,@GLOBALGROUP,1))
   ErrorMode(ErrMode)
   llist = StrLower(wntMemberList("","Administrators",@LOCALGROUP))
   ngroups = ItemCount(llist,@TAB)
   For i = 1 To ngroups
      lgroup = ItemExtract(i,llist,@TAB)
      If ItemLocate(lgroup,glist,@TAB)>0
         Admin = @TRUE
         Break
      EndIf
   Next
EndIf

Message("Admin",Admin)

Please note that the admin check above will fail if the global groups must be checked and the machine is not online. Therefore, I prefer to just test the user's rights directly. I've been using the function below to test for admin rights for years and it has never failed me. Of course it can be fooled if someone gives a non-admin user rights to the specific registry key I'm checking, but that's an extremely unlikely event.

#DefineFunction AdminUser() ; Check for Admin rights
Admin = @FALSE
KeyVal = "System\CurrentControlSet\Control[Admin]"
ErrMode = ErrorMode(@FALSE)
RegSetValue(@REGMACHINE,KeyVal,"1")
Admin = RegQueryValue(@REGMACHINE,KeyVal)
RegDelValue(@REGMACHINE,KeyVal)
ErrorMode(ErrMode)
If Admin=="1" Then Admin = @TRUE
Return Admin
#EndFunction

Message("Admin",AdminUser())

Article ID:   W17993
Filename:   Check if You Have Local Admin Rights .txt
File Created: 2009:04:09:12:54:22
Last Updated: 2009:04:09:12:54:22