(view source code of user2sid.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF "%~1"=="" GOTO Syntax
IF NOT "%~2"=="" GOTO Syntax
SETLOCAL
ECHO.%~1 | FIND "\" >NUL
IF ERRORLEVEL 1 (
SET Domain=%UserDomain%
SET Name=%~1
) ELSE (
FOR /F "tokens=1,2 delims=\ " %%A IN ("%~1") DO (
SET Domain=%%A
SET Name=%%B
)
)
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_UserAccount Where "(Domain='%Domain%' And Name='%Name%')" Get SID /Format:list ^| FIND "="') DO SET %%A
ECHO.%SID%
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO User2SID.bat, Version 1.00 for Windows XP Professional and later
ECHO Return the SID of the specified user ID
ECHO.
ECHO Usage: USER2SID [domain\]userid
ECHO.
ECHO Note: if no domain is specified, %%UserDomain%% will be assumed
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
page last modified: 2024-04-16; loaded in 0.0089 seconds