Skip navigation

JSI Tip 1211. Who is logged on locally?


If it is not convenient to press CTRL+ALT+DEL (or the OS doesn't support it), type (on your Windows NT computer):

WhoLocal ComputerName

where ComputerName is the NetBIOS name of the computer you want to check.

WhoLocal.bat will echo a user=xxxxx where xxxxx is the locally logged on UserName (or null if no one is logged on locally). If UserName is logged on locally, it will set a user environment variable. You may also receive:

A session does not exist with that computer name.

which can be ignored.

WhoLocal.bat contains:


@echo off
setlocal
set machine=%1
set user=
If \{%1\}

\{\} goto syntax for /f "Tokens=*" %%i in ('net sess \\%machine%') do call :user1 "%%i" if not "%user%"

"" goto done for /f "Skip=5 Tokens=*" %%i in ('nbtstat -a %machine%') do call :user2 "%%i" :done @echo user=%user% endlocal & set user=%user% goto end :syntax @echo Syntax: WhoLocal ComputerName endlocal & set user= goto end :user1 if not "%user%"

"" goto end set param=%1 set param=%param:"=% set param=%param: =% set param1=%param:~0,8% if not "%param1%"

"Username" goto end set user=%param:~8,21% goto end :user2 if not "%user%"=="" goto end set param=%1 set param=%param:

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