Skip navigation

JSI Tip 0981. Where is UserName logged on from?


In tip 595, we scripted Whoison.bat to build a file of all currently logged on users.

JSIWhereIs.bat will locate a user, or users, if they are logged on, and display the ComputerName and Platform they are logged on from.

The syntax is:

JSIWhereIs User1 \[User2 User3 ... UserN\]

JSIWhereIs.bat contains:

   
@echo off
setlocal
if NOT "%1"

"" goto begin :syntax @echo Syntax: JSIWhereIs UserName1 \[UserName2 ... UserNameN\] endlocal goto end :begin if "%1"

"" endlocal & goto end set user=%1 set user=%user:"=% shift for /f "Skip=4 Tokens=*" %%i in ('net session') do call :parse "%%i" goto begin :parse set str=%1 set str=%str:"=% if "%str%"

"The command completed successfully." goto end for /f "Tokens=*" %%i in ('@echo %%str:~23^,20%%') do set substr=%%i? if "%substr%"

"ECHO is on.?" goto end set substr=%substr: =% set substr=%substr: ?=% set substr=%substr:?=% if /i not "%user%"=="%substr%" goto end @echo %str% :end

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