Skip navigation

JSI Tip 7429. What profiles exist on a computer?


Using REG.EXE on Windows 2000, from the Windows 2000 Support Tools, or REG.EXE built into Windows XP and later, and the SIDTONAME freeware, I have scripted ProfileList.bat, to retrieve the SID and UserName of all the profiles on a specified computer.

The syntax for using ProfileList.bat is:

ProfileList \\ComputerName

where ComputerName can be local or remote.

NOTE: If you wish to process the list in a batch file, use the following syntax:

for /f "Tokens=1*" %%s in ('ProfileList \\ComputerName') do set SID=%%s&set User=%%t&call :YourLabel

If you use the ProfileList \\ComputerName syntax, the console output is similar to:

S-1-5-18 "NT AUTHORITY\SYSTEM"
S-1-5-19 "NT AUTHORITY\LOCAL SERVICE"
S-1-5-20 "NT AUTHORITY\NETWORK SERVICE"
S-1-5-21-4032795696-1918355027-149915103-500 "JSI009\Administrator"
S-1-5-21-4134520471-696337240-1581626817-1137 "JSIINC\Jerry"
ProfileList.bat contains:
@echo off
setlocal
If \{%1\}==\{\} goto syntax
set computer=%1
set computer=\\%computer:\=%
if not exist %computer%\c$ goto syntax
for /f "Skip=3 Tokens=*" %%i in ('reg QUERY "%computer%\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /s') do set line=%%i&call :IsSID
endlocal
goto :EOF
:syntax
@echo Syntax ProfileList \\ComputerName
endlocal
goto :EOF
:IsSID
set SID=%line:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\=%
If "%SID%" EQU "%line%" goto :EOF
set user=Unknown
for /f "Tokens=*" %%u in ('SIDTONAME %SID%') do set user=%%u
@echo %SID% "%user%"



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