查找登录到远程计算机的用户 [英] Find User Logged on to a Remote Computer

查看:25
本文介绍了查找登录到远程计算机的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本.它应该找到当前登录到远程计算机的用户,但它没有.我错过了什么?远程计算机是域的一部分.我会看到添加域吗?怎么样?

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 记录 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

这篇关于查找登录到远程计算机的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆