Find User Logged on to a Remote Computer
我有以下脚本。它应该找到当前登录到远程计算机的用户,但它没有。我错过了什么?远程计算机是域的一部分。我会看到添加域吗?怎么样?
1 2 3 4 5 6 7 8 9 10 11 | strComputer ="computername" Set objWMIService = GetObject("winmgmts:" _ &"{impersonationLevel=impersonate}!\" & strComputer &"\ oot\\cimv2") Set colComputer = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colComputer Wscript.Echo"Logged-on user:" & objComputer.UserName Next |
如文档所述,
UserName
[...]
Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session.
如果您没有得到结果,您的用户很可能是通过远程桌面登录的。
要让所有用户登录远程系统,请检查其所有者正在运行的资源管理器进程:
1 2 3 4 5 6 7 8 9 10 | strComputer ="computername" Set objWMIService = GetObject("winmgmts:" _ &"{impersonationLevel=impersonate}!\" & strComputer &"\ oot\\cimv2") qry ="SELECT * FROM Win32_Process WHERE Name='explorer.exe'") For Each p in objWMIService.ExecQuery(qry) p.GetOwner user, domain WScript.Echo"Logged-on user:" & domain &"" & user Next |