JSI Tip 8277. How can my script determine who is logged onto the console of a remote computer?

I have scripted WhoConsole.bat and WhoConsole.vbs to determine the user that is logged onto the console of a remote computer.

The syntax for using WhoConsole.bat is:

call WhoConsole ComputerName UserName

Where ComputerName is the NetBIOS name of the computer, and UserName is a call directed environment variable that will contain the logged on user, or null, if nobody is logged on, or if the ComputerName is NOT found.

NOTE: WhoConsole.bat and WhoConsole.vbs must be located in the same folder.

WhoConsole.bat contains:

@echo off
if \{%2\}==\{\} goto err
set comp=%1
set user=null
set comp=%comp:\=%
set wc="%~DP0WhoConsole.vbs"
if not exist %wc% goto nowc
call :quiet>nul 2>&1
if "%r2%" NEQ "" goto sr2 
if "%r1%" EQU "" goto finish
set user=%r2%
endlocal&set %2=%user%
goto :EOF
for /f "Tokens=1* Delims=\" %%t in ('cscript //NOLOGO %wc% %comp%') do (
 set r1=%%t
 set r2=%%u
goto :EOF
@echo syntax WhoConsole Computer User
goto :EOF
@echo WhoConsole.bat - Cannot locate WhoConsole.vbs
WhoConsole.vbs contains:
dim ComputerName, Users
Dim objArgument
Set objArgument = Wscript.Arguments
who = "winmgmts:\{impersonationLevel=impersonate\}!//"& ComputerName &""
Set Users = GetObject( who ).InstancesOf ("Win32_ComputerSystem")
for each User in Users
	Wscript.echo User.UserName

Hide 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.