且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找登录到远程计算机的用户

更新时间:2022-03-04 07:30:31

As 记录 UserName 属性返回登录到控制台的用户的名称:

As documented the UserName property returns the name of the user logged in on the console:

用户名
[...]
当前登录的用户名.此属性必须具有值.在终端服务会话中,UserName 返回登录到控制台的用户的名称,而不是在终端服务会话期间登录的用户.

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.

如果您没有得到结果,您的用户很可能是通过远程桌面登录的.

If you don't get a result your user is most likely logged in via Remote Desktop.

让所有用户登录远程系统 检查其所有者正在运行的 Explorer 进程:

To get all users logged in on the remote system check the running Explorer processes for their owners:

strComputer = "computername"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\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