Batch NET WHO command replacement

NET WHO command replacement

@ECHO OFF
:: NET WHO command replacement for Windows NT
:: Version 2.10 B
:: Written by Rob van der Woude

:: Keep variables local
SETLOCAL

:: Find domain name
FOR /F "TOKENS=*" %%A IN ('NET USER %USERNAME% /DOMAIN ^| FIND /I "or dom"') DO FOR %%V IN (%%A) DO SET DOMAIN=%%V
FOR /F "TOKENS=1* DELIMS=." %%A IN ('ECHO.%DOMAIN%') DO SET DOMAIN=%%A

:: Find all PCs and display logged on user for each PC
FOR /F "TOKENS=1* DELIMS=\" %%A IN ('NET VIEW /DOMAIN:%DOMAIN%') DO CALL :Who %%A

:: End program
ENDLOCAL
GOTO:EOF

:Who
:: Display logged on user for each PC
FOR /F %%B IN ('NBTSTAT -a %1 ^| FIND "UNIQUE" ^| FIND /V /I "%1" ^| FIND /V /I "%DOMAIN%"') DO ECHO  %1    %%B
GOTO:EOF