Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录到终端服务器的用户的vbscript列表_Vbscript - Fatal编程技术网

登录到终端服务器的用户的vbscript列表

登录到终端服务器的用户的vbscript列表,vbscript,Vbscript,尝试通过vbscript在工作组中列出登录到windows终端服务器的用户 我有下面的,但它似乎没有返回登录的用户 strComputer = "." Set objWMI = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colSessions =

尝试通过vbscript在工作组中列出登录到windows终端服务器的用户

我有下面的,但它似乎没有返回登录的用户

strComputer = "."  

Set objWMI = GetObject("winmgmts:" _ 
              & "{impersonationLevel=impersonate}!\\" _ 
              & strComputer & "\root\cimv2") 

Set colSessions = objWMI.ExecQuery _ 
    ("Select * from Win32_LogonSession Where LogonType = 10") 

If colSessions.Count = 0 Then 
   Wscript.Echo "No interactive users found" 
Else 
   WScript.Echo "RDP Sessions:"
   For Each objSession in colSessions 

     Set colList = objWMI.ExecQuery("Associators of " _ 
         & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _ 
         & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" ) 
     For Each objItem in colList 
       WScript.Echo "Username: " & objItem.Name & " FullName: " & objItem.FullName 
     Next 
   Next 
End If

您必须以管理员身份运行它!
以管理员身份运行CMD并运行命令CSCRIPT

在我测试本地交互式登录时起作用(
LogonType=2
)。你确定有RDP用户登录到运行此脚本的主机吗?是的-我有2个用户登录,但没有找到任何用户。尝试使用10和2。您是否得到“未找到交互用户”或只是没有列出会话?您是否尝试按登录类型列出所有登录会话?我收到:RDP会话消息,然后出现错误:第19行字符:6,如果我从LogonType中删除where,则会出现相同的错误。您的脚本在Terminal Server 2003中运行良好,只是我是唯一使用RDP登录的用户,但它显示了我的登录4次。使用Server2008R2 Ent,它正确显示rdp会话的名称,没有错误。