Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for remotesid.bat

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

  1. @ECHO OFF
  2. :: Check OS version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: For Windows NT 4/2000
  6. SETLOCAL ENABLEEXTENSIONS
  7.  
  8. :: Check command line parameter
  9. :: Delims is a backslash, followed by a TAB and a space
  10. FOR /F "tokens=1 delims=\	 " %%A IN ('ECHO.%*') DO SET Host=%%A
  11. IF "%Host%"=="" GOTO Syntax
  12. PING %Host% | FIND "TTL=" >NUL
  13. IF ERRORLEVEL 1 GOTO Syntax
  14.  
  15. :: Find out who is logged on to the remote computer
  16. SET UserID=
  17. FOR /F "skip=6 eol=U tokens=1* delims=\" %%A IN ('PSLOGGEDON \\%Host% ^| FIND /V "NT AUTHORITY"') DO CALL :UserID %%B
  18.  
  19. :: Find out the remote user's Security ID
  20. FOR /F "tokens=7 delims= " %%A IN ('GETSID \\%Host% %UserID% \\%Host% %UserID% ^| FIND " is "') DO SET SID=%%A
  21.  
  22. :: Display the values
  23. SET Host
  24. SET UserID
  25. SET SID
  26.  
  27. ::Done
  28. GOTO End
  29.  
  30. :UserID
  31. IF NOT DEFINED UserID SET UserID=%1
  32. GOTO:EOF
  33.  
  34. :Syntax
  35. ECHO.
  36. ECHO RemoteSID.bat,  Version 2.11 for Windows NT 4 / 2000
  37. ECHO Display remote PC's logged on user and Security ID
  38. ECHO.
  39. IF     "%OS%"=="Windows_NT" ECHO Usage:  %~n0  \\remote_hostname
  40. IF NOT "%OS%"=="Windows_NT" ECHO Usage:  %0  \\remote_hostname
  41. ECHO.
  42. ECHO Written by Rob van der Woude
  43. ECHO http://www.robvanderwoude.com
  44. ECHO.
  45. ECHO Note: Uses GETSID.EXE from the Microsoft Windows NT 4 Resource Kit
  46. ECHO       http://www.microsoft.com
  47. ECHO       Also uses PSLOGGEDON.EXE Version 1.5 from SysInternals.com
  48. ECHO       http://www.sysinternals.com
  49.  
  50. :End
  51. ENDLOCAL
  52. IF "%OS%"=="Windows_NT" ENDLOCAL
  53.  

page last uploaded: 2017-08-21, 14:26