tags:

views:

24

answers:

1

I want to use System.Management.ManagementScope to query the list of currently logged in users.

This will be part of a larger application that we will deploy to our customers, so it needs to be easy to setup and highly reliable.

Is ManagementScope/WMI a good fit? Should it always be available to query on most OSes? Are there any security concerns I have to consider, say for example a non-elevated user logs into a workstation, will that user be able to query the WMI? Will a system account running as a service?

Any other gotchas I should know about before going this route?

Thanks

+1  A: 

System account running a service is the way we handle it, as not all users are local admins. We push the service out at the same time as the GUI and talk to it via IPC channels. It works, and it's easier than worrying about which scopes users can see within WMI. In our case, it also facilitates writing to the event log.

WMI is probably the easiest way to do it. You could look at pinvoke / the Win32 API (or potentially even the Terminal Server API's) but WMI is likely the easiest to get up and running reliably.

The only issues I've ever run into with WMI is speed - although I usually encounter these with hardware queries which are too broad, so I think it's potentially my bad there.

AFAIK, Windows 2000 and below will need a different query than Windows XP and above, as with XP and above you query Win32_LogonSession for results where LogonType=2 (interactive). As 2000 and below only support a single logged on console user, you would just query Win32_ComputerSystem and get the UserName property for the returned result.

dotalchemy