Powered by GeSHi

Source code for user2sid.bat

(view source code of user2sid.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. IF      "%~1"=="" GOTO Syntax
  4. IF NOT  "%~2"=="" GOTO Syntax
  5.  
  6. SETLOCAL
  7. ECHO.%~1 | FIND "\" >NUL
  8. IF ERRORLEVEL 1 (
  9. 	SET Domain=%UserDomain%
  10. 	SET Name=%~1
  11. ) ELSE (
  12. 	FOR /F "tokens=1,2 delims=\ " %%A IN ("%~1") DO (
  13. 		SET Domain=%%A
  14. 		SET Name=%%B
  15. 	)
  16. )
  17. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_UserAccount Where "(Domain='%Domain%' And Name='%Name%')" Get SID /Format:list ^| FIND "="') DO SET %%A
  18. ECHO.%SID%
  19. ENDLOCAL
  20. GOTO:EOF
  21.  
  22.  
  23. :Syntax
  24. ECHO.
  25. ECHO User2SID.bat,  Version 1.00 for Windows XP Professional and later
  26. ECHO Return the SID of the specified user ID
  27. ECHO.
  28. ECHO Usage:  USER2SID  [domain\]userid
  29. ECHO.
  30. ECHO Note:   if no domain is specified, %%UserDomain%% will be assumed
  31. ECHO.
  32. ECHO Written by Rob van der Woude
  33. ECHO http://www.robvanderwoude.com
  34.