And*_*ija 37 windows command-line-interface users
环境在域中,服务器是Windows Server 2003,工作站安装了Vista 和XP。
我需要远程检查谁当前登录工作站的方法,最好是从一些简单的命令行而不是 sysinternals 或第三方程序。
谢谢
Pre*_*gha 47
这是原始来源,但现在是 404 :
他们建议使用 Windows 上可用的(Windows 管理界面命令)WMIC:
WMIC /NODE: xxx.xxx.xxx.xxx COMPUTERSYSTEM GET USERNAME
Run Code Online (Sandbox Code Playgroud)
将返回当前登录到 xxx.xxx.xxx.xxx 的用户名,或
WMIC /NODE: "workstation_name" COMPUTERSYSTEM GET USERNAME
Run Code Online (Sandbox Code Playgroud)
将返回当前登录到“workstation_name”的用户名
更新:这也应该适用于 Windows 10 - 如果您是远程机器上的管理员。
nik*_*nik 17
抱歉,没有注意到您不想使用 Sysinternals。
那现在是 Microsoft technet 工具,有什么不使用它的具体原因吗?
在Mark Russinovich进入 Microsoft之前,我更喜欢 Sysinternals 而不是其他第三方工具。
在微软的Sysinternals套房有一个叫做工具Psloggedon,
psloggedon.exe -l
Run Code Online (Sandbox Code Playgroud)
还有NBTSTAT,
nbtstat -a NetBIOS-Computer-NAme
Run Code Online (Sandbox Code Playgroud)
MDM*_*313 12
我使用了 win32_loggedonuser,但遇到了返回多个域用户的问题,因此它不适合我的目的。相反,我使用了(在 powershell 中)
#Get Currently logged in user
$ExplorerProcess = gwmi win32_process | where name -Match explorer
if($ExplorerProcess.getowner().user.count -gt 1){
$LoggedOnUser = $ExplorerProcess.getowner().user[0]
}
else{
$LoggedOnUser = $ExplorerProcess.getowner().user
}
Run Code Online (Sandbox Code Playgroud)
if 是因为有时 getowner 会出于某种原因报告多个用户,不知道为什么,但在我的情况下,它是同一个用户,所以这不是问题。
小智 6
您可以从 win32_loggedonuser 获取此信息。
从这个页面:
strComputer = "." ' " use "." for local computer
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSessions = objWMI.ExecQuery _
("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")
If colSessions.Count = 0 Then
Wscript.Echo "No interactive users found"
Else
For Each objSession in colSessions
If objSession.LogonType = 2 Then
WScript.Echo "Logon type: Console"
Else
WScript.Echo "Logon type: RDP/Terminal Server"
End If
Set colList = objWMI.ExecQuery("Associators of " _
& "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _
& "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )
For Each objItem in colList
WScript.Echo "User: " & objItem.Name
WScript.Echo "FullName: " & objItem.FullName
WScript.Echo "Domain: " & objItem.Domain
Next
Wscript.Echo "Session start time: " & objSession.StartTime
WScript.Echo
Next
End If
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
412267 次 |
| 最近记录: |