VB Using WMI - Log In Users

How can I use VB scripts with WMI to get # registered users. My installation can only be registered by one user and should report an error if more than one user is registered (via Terminal Services using Citrix). I don't know much about Citrix, but Win32_LogonSession with LogonType = 10 seems to return all kinds of unwanted ones (port sessions, etc.). I just need users ... are there any WMI calls I can just get so that the number of users is registered with Citrix? Below is a snippet of my VB code:

 Set objWMIService = _ GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colComputer = _ objWMIService.ExecQuery("Select * from Win32_LogonSession Where LogonType = 10") 

Thanks! -jp

+3
source share
1 answer

The following code should help you (use strComputer="." For the local computer or strComputer="MachineName" ):

 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 

The original code is here:

How to show registered users? (Tek-Tips Forums)

This worked with Windows 2003, I can not guarantee any guarantees regarding a later version.

+3
source

All Articles