Skip navigation

JSI Tip 9525. What is the local administrtator's name on my computer?


The default name of the local built-in administrator account is Administrator.

If you rename the Administrator account, the SID and RID of the account do not change.

I have scripted gAdmin.bat to determine the name of the local built-in administrator account.

The syntax for using gAdmin.bat is:

call gAdmin VarName

Where VarName is a call directed environment variable that will contain the local built-in administrator account name.

gAdmin.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: gADMIN VarName&goto :EOF
setlocal
set wrk="%TEMP%\gADMIN.vbs"
if exist %wrk% goto getadmin
@echo Set objArgument = Wscript.Arguments>%wrk%
@echo cName=objArgument(0)>>%wrk%
@echo admin = gAdmin(cName)>>%wrk%
@echo Wscript.Echo admin>>%wrk%
@echo On Error Resume Next>>%wrk%
@echo.>>%wrk%
@echo Function gAdmin(cName)>>%wrk%
@echo Dim uSID, wnWK, oAcct>>%wrk%
@echo Set oAccts = GetObject("winmgmts:\{impersonationLevel=impersonate\}!//" ^& cName ^& "/root/cimv2").ExecQuery( _>>%wrk%
@echo        "Select Name, SID from Win32_UserAccount WHERE Domain = '" ^& cName ^& "'")>>%wrk%
@echo On Error Resume Next>>%wrk%
@echo For Each oAcct In oAccts>>%wrk%
@echo   If Left(oAcct.SID, 9) = "S-1-5-21-" And _>>%wrk%
@echo      Right(oAcct.SID, 4) = "-500" Then>>%wrk%
@echo        gaDMin = oAcct.Name>>%wrk%
@echo Exit For>>%wrk%
@echo End if>>%wrk%
@echo Next>>%wrk%
@echo End Function>>%wrk%
:getadmin
set admin=NONE
for /f "Tokens=*" %%a in ('cscript //nologo %wrk% %ComputerName%') do (
 set admin=%%a
)
endlocal&set %1=%admin%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish