Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For finding things / generating WMI code and queries, get the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=2cc30a64-ea15-4661-8da4-55bbc145c30e&amp;displaylang=en" rel="nofollow noreferrer">WMI Code Creator</a>. It will generate the test stubs (C#, VB.NET, VBScript) and let you test out queries to make sure they return the info you want. </p> <p>Terminal Services stuff under the Win32_Terminal* and Win32_TS* classes (There are a few of them, not sure which is the one that get you what you need. ).</p> <p>I also use this helper class (needs a bit of refactoring, haven't touched it in years) to get management objects and execute methods. </p> <pre><code>using System; using System.Collections.Generic; using System.Text; using System.Management; namespace MyWMI { public class WmiHelper { public static ManagementObjectCollection GetManagementObjectCollection(string ServerName, string WMIQuery) { //determine where the WMI root is that we will connect to. string strNameSpace = "\\\\"; ConnectionOptions connectionOptions = new ConnectionOptions(); TimeSpan tsTimeout = new TimeSpan(0,0,5); connectionOptions.Timeout = tsTimeout; //if its not a local machine connection if (ServerName.Trim().ToUpper() != Globals.HostName) { strNameSpace += ServerName; connectionOptions.Username = Globals.WMIUserDomain + "\\" + Globals.WMIUserName; connectionOptions.Password = Globals.WMIUserPass; } else { //we are connecting to the local machine strNameSpace += "."; } strNameSpace += "\\root\\cimv2"; //create the scope and search ManagementScope managementScope = new ManagementScope(strNameSpace, connectionOptions); ObjectQuery objectQuery = new ObjectQuery(WMIQuery); ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, objectQuery); ManagementObjectCollection returnCollection; try { returnCollection = searcher.Get(); } catch (ManagementException ex) { throw new SystemException("There was an error executing WMI Query. Source: " + ex.Source.ToString() + " Message: " + ex.Message); } //return the collection return returnCollection; } //eng GetManagementObjectCollection public static bool InvokeWMIMethod(string ServerName, string WMIQueryToIsolateTheObject, string MethodName, object[] MethodParams) { //determine where the WMI root is that we will connect to. string strNameSpace = "\\\\"; ConnectionOptions connectionOptions = new ConnectionOptions(); TimeSpan tsTimeout = new TimeSpan(0, 0, 5); connectionOptions.Timeout = tsTimeout; if (ServerName.Trim().ToUpper() != Globals.HostName) { strNameSpace += ServerName; connectionOptions.Username = Globals.WMIUserDomain + "\\" + Globals.WMIUserName; connectionOptions.Password = Globals.WMIUserPass; } else { //we are connecting to the local machine strNameSpace += "."; } strNameSpace += "\\root\\cimv2"; ManagementScope managementScope = new ManagementScope(strNameSpace, connectionOptions); ObjectQuery objectQuery = new ObjectQuery(WMIQueryToIsolateTheObject); ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, objectQuery); ManagementObjectCollection returnCollection = searcher.Get(); if (returnCollection.Count != 1) { return false; } foreach (ManagementObject managementobject in returnCollection) { try { managementobject.InvokeMethod(MethodName, MethodParams); } catch { return false; } } //end foreach return true; } //end public static bool InvokeWMIMethod(string ServerName, string WMIQueryToGetTheObject, string MethodName, object[] MethodParams) } } </code></pre> <p><strong>@First comment:</strong> Ick... Apparently this <em>is</em> more complicated than first thought. Check this article (<a href="http://www.codeproject.com/KB/system/logonsessions.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/system/logonsessions.aspx</a>), in the section titled "<em>What about the built-in WMI functionality?</em>". There is some special handling needed if using XP, because it has different WMI provider classes (change WMI Code creator to point to a remote computer - A Win2K3 server for instance), and in either case you will need to "join" data from all of the session classes. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload