I first scripted Whereis.bat at Where is <Username>?

Using PsLoggedOn.exe freeware, I have scripted a revised Whereis.bat.

The syntax for using Whereis.bat is:

for /f "Tokens=1,2 Delims=," %%a in ('<b>Whereis UserName</b>') do (
 set <b>usr</b>=%%a
 set <b>cmp</b>=%%b
 call :DoSomeThing
Where UserName is the sAMAccountName name, like Jerry.

NOTE: If a user is logged on to more than one computer, your :DoSomeThing routine will be called more than once.

NOTE: If Jerry is logged onto the JSIINC domain from computer JSI009, usr will be set to "JSIINC\Jerry" and cmp will be set to "JSI009".

Whereis.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax Whereis UserName&goto :EOF
set user=%1
set file="%TEMP%\Whereis_%RANDOM%.TMP"
call :quiet>nul 2>&1
for /f "Tokens=*" %%a in ('type %file%^|find "\"') do (
 set line=%%a
 set line=!line: logged onto =#!
 set line=!line: locally.=!
 for /f "Tokens=1* Delims=#" %%u in ('@echo !line!') do (
  set wrk=%%u
  set cmp=%%v
  set usr=!wrk:*%USERDOMAIN%\=%USERDOMAIN%\!
  if "!usr!" EQU "!wrk!" set usr=!wrk:*%%v\=%%v\!
  @echo "!usr!","!cmp!"
del /q %file%
goto :EOF
psloggedon -L %user% >%file%