I have the following script. It should find the user who is currently logged into remote computer, but it doesn't. What am I missing? The remote computer is a part of a domain. Would I see to add the domain? How?
strComputer = "computername"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
Wscript.Echo "Logged-on user: " & objComputer.UserName
Next
As documented the
UserName
property returns the name of the user logged in on the console:If you don't get a result your user is most likely logged in via Remote Desktop.
To get all users logged in on the remote system check the running Explorer processes for their owners: