Who’s a Local Adminstrator?

Here’s VBScript code you can use in a login script or from SMS to find out who has administrator rights on a PC:

‘ Variables
Dim objFileSystem, objOutputFile
Dim strOutputFile

‘ Init objects
Set Shell = CreateObject(“WScript.Shell”)
Set oNet= WScript.CreateObject(“WScript.Network”)
Set filesys = CreateObject(“Scripting.FileSystemObject”)

‘ Grab computername
computername = Shell.ExpandEnvironmentStrings(“%computername%”)

‘ See if we can do something “Admin” like
if filesys.FolderExists(“\” & computername & “Admin$System32”) then
‘ Grab username
oUser = oNet.UserName
‘ Set filename to computername.username.txt
strOutputFile=computername & “.” & oUser & “.txt”
Set objOutputFile = filesys.CreateTextFile(strOutputFile, TRUE)
‘Close file
objOutputFile.Close
Set objFileSystem = Nothing
end if

Only users with administrator rights can get to administrative shares. So if we can get to \mycomputerAdmin$System32: we are an administrator. The script then writes out the logged in user’s name to a file in the format of computername.username.txt.


Note: The appending of .txt is purely for cosmetic reasons. The script comes from two parts of source code I “stole” from the Internet. Also, if you want the file written out to a specific server share: append \yourserveryourshare before computername set by strOutputFile

Soli Deo Gloria

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.