WIN32_OperatingSystem的WMI服务中系统正常运行时间的属性名称 [英] Property Name for System Up time in WMI service of WIN32_OperatingSystem

查看:305
本文介绍了WIN32_OperatingSystem的WMI服务中系统正常运行时间的属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#代码使用以下代码来获取所有远程计算机的系统正常运行时间.

I am working on C# code to get the system up time of any remote machines with the following code.

ConnectionOptions connOptions = new ConnectionOptions();
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            ManagementScope manScope = new ManagementScope(@"\\myshec79920d\ROOT\CIMV2", connOptions);
            manScope.Connect();
            ObjectGetOptions objectGetOptions = new ObjectGetOptions();
            ManagementPath managementPath = new ManagementPath("Win32_OperatingSystem");
            ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
            foreach (ManagementObject item in processClass.GetInstances())
            {
                Console.WriteLine(item["SystemTime"]);
            }



在上面的代码中,我们可以使用



In the above code what property name we can give as

item["--"] 

获取系统正常运行时间(重新启动时间)

请帮我解决这个问题.在此先谢谢您

to get the system up time(reboot time)

Please help me out to solve this. Thanks in advance

推荐答案

您自己查找的速度可能比我在
You can probably look it up yourself faster than I can type this in http://msdn.microsoft.com/en-us/library/aa394572(v=vs.85)[^] but if you''re too busy try the LastBootUpTime property.

Alan.


替代解决方案:
需要添加的库是
Alternate solution:
Library needs to be inlcded is
System.Management


ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(string.Format(@"\\{0}\ROOT\CIMV2",serverName), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_OperatingSystem");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
foreach (ManagementObject item in processClass.GetInstances())
{
    Console.WriteLine(item["LastBootUpTime"].ToString());
}


对于

ConnectionOptions

,我们可以提供用于安全连接的域,用户名和密码.

we can provide Domain, User Name and password for secure connections.


这篇关于WIN32_OperatingSystem的WMI服务中系统正常运行时间的属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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