I want to query our servers to see look for disconnected/idle sessions. I know I can use 'query.exe', but I'd prefer something that's easier to work with from code.
WMI would be my preference.
Thanks.
I want to query our servers to see look for disconnected/idle sessions. I know I can use 'query.exe', but I'd prefer something that's easier to work with from code.
WMI would be my preference.
Thanks.
If you are using a .NET language, you might try Cassia. In C#, the code would be:
EDIT: Updated sample code for Cassia 2.0.
For finding things / generating WMI code and queries, get the WMI Code Creator. 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.
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. ).
I also use this helper class (needs a bit of refactoring, haven't touched it in years) to get management objects and execute methods.
@First comment: Ick... Apparently this is more complicated than first thought. Check this article (http://www.codeproject.com/KB/system/logonsessions.aspx), in the section titled "What about the built-in WMI functionality?". 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.