WMI获取所有用户状态 [英] WMI get all users state

查看:116
本文介绍了WMI获取所有用户状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试获取所有用户的状态或状态,不确定属性名称是什么.
我为userName属性找到了以下代码:

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:

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

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 :-)

推荐答案

此列表列出了所有
This list all the properties[^] of the Win32_ComputerSystem class.

See if it contains one that contains what you need.


这篇关于WMI获取所有用户状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆