Answers:
这是原始来源,但现在是404:
他们建议使用Windows上可用的(Windows管理界面命令)WMIC:
WMIC /NODE: xxx.xxx.xxx.xxx COMPUTERSYSTEM GET USERNAME
将返回当前登录到xxx.xxx.xxx.xxx的用户名,或
WMIC /NODE: "workstation_name" COMPUTERSYSTEM GET USERNAME
将返回当前登录“ workstation_name”的用户名
更新:如果您是远程计算机上的管理员,这也应该在Windows 10上也可以使用。
抱歉,没有注意到您不想使用Sysinternals。
那就是现在的Microsoft technet工具,有什么特定原因不使用它吗?
在Mark Russinovich进入Microsoft 之前,我比其他第三方工具更喜欢Sysinternals 。
在微软的Sysinternals套房有一个叫做工具Psloggedon,
psloggedon.exe -l
还有NBTSTAT,
nbtstat -a NetBIOS-Computer-NAme
WMIC
被接受的答案抱怨RPC没有运行。那是一盒新的蠕虫,我现在不想打开,所以我检查了psloggedon,我感到非常高兴。
我使用过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
}
如果是因为有时getowner出于某种原因会报告多个用户,不知道为什么,但是在我的情况下,该用户是同一用户,所以这不是问题。
您可以从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
UserName
,即使我已登录到该计算机,也仅得到一行输出“ ”,未列出其他任何内容。