Skip navigation

JSI Tip 9743. Where is <Username>?


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 ('Whereis UserName') do (
 set usr=%%a
 set cmp=%%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
setlocal ENABLEDELAYEDEXPANSION
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%
endlocal
goto :EOF
:quiet
psloggedon -L %user% >%file%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish