Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm trying to get all the users state or status, not sure what is the property name.
I found this code for the userName property:
C#
ConnectionOptions options = new ConnectionOptions();
                options.EnablePrivileges = true;
                ManagementScope scope = new ManagementScope("\\\\" + fqdn + "\\root\\CIMV2", options);
                scope.Connect();

                SelectQuery query = new SelectQuery("Win32_ComputerSystem");
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher(scope, query);
                string machineUser = "";
                foreach (ManagementObject os in searcher.Get())
                {
                    machineUser +=" "+ os.GetPropertyValue("username").ToString();
                }

I would like to also have the user state, if the user is on sleep, inactive, active etc.
Where can I find it?
Thanks in advance :-)


------

one more thing, when no user is logged on
C#
os.GetPropertyValue("username").ToString();
throws an exception.
Is that the expected behavior? How can I tell if that's the reason or it's something else?
If I could just have the users and their status, that would have been great :-)
Posted
Updated 26-Nov-12 0:22am
v3

1 solution

This list all the properties[^] of the Win32_ComputerSystem class.

See if it contains one that contains what you need.
 
Share this answer
 
Comments
dontforgettobreathe 25-Nov-12 12:57pm    
well, I've seen this list before and tried some of the properties via WMI code creator, also some other win32 classes. Still havn't found what I need.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900