WMI获取所有用户状态 [英] WMI get all users state
问题描述
我正在尝试获取所有用户的状态或状态,不确定属性名称是什么.
我为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 theWin32_ComputerSystem
class.
See if it contains one that contains what you need.
这篇关于WMI获取所有用户状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!