Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for netwho.bat

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

  1. @ECHO OFF
  2. :: NET WHO command replacement for Windows NT
  3. :: Version 2.10
  4. :: Written by Rob van der Woude
  5. :: Dependencies: Assumes PC IDs start with "PC"
  6.  
  7. :: Keep variables local
  8. SETLOCAL
  9.  
  10. :: Find domain name
  11. FOR /F "TOKENS=*" %%A IN ('NET USER %USERNAME% /DOMAIN ^| FIND /I "or dom"') DO FOR %%V IN (%%A) DO SET DOMAIN=%%V
  12. FOR /F "TOKENS=1* DELIMS=." %%A IN ('ECHO.%DOMAIN%') DO SET DOMAIN=%%A
  13.  
  14. :: Find all PCs and display logged on user for each PC
  15. FOR /F "TOKENS=1* DELIMS=\" %%A IN ('NET VIEW /DOMAIN:%DOMAIN% ^| FIND "\\PC"') DO CALL :Who %%A
  16.  
  17. :: End program
  18. ENDLOCAL
  19. GOTO:EOF
  20.  
  21. :Who
  22. :: Display logged on user for each PC
  23. FOR /F %%B IN ('NBTSTAT -a %1 ^| FIND "UNIQUE" ^| FIND /V /I "%1" ^| FIND /V /I "%DOMAIN%"') DO ECHO  %1    %%B
  24. GOTO:EOF
  25.  

page last modified: 2024-04-16; loaded in 0.0078 seconds