Accessing Management Information with System.Management(Chapter 2)

简介:
                     How To Retrive Collections Of Management Objects
    The following code example uses the System.Management collection classes to enumerate environment variables on a computer. Some parameters can be left to default values in this example because the example gets information from the local computer. The managementscope class will be used if the information gets from romoting computer.
   There are tow way to demostrate how to enumerate the collection of 'win32_environment'.
   Synchronous way:
 
public void DoSynchronous()
{
            //SelectQuery is inherited from ManagementQuery.
            //The description about ManagementQuery in chapter 1
           SelectQuery query = new SelectQuery("WIN32_Environment");

            ManagementObjectSearcher mObjSearch = new ManagementObjectSearcher(query);
            int count = mObjSearch.Get().Count;
            //ManagementBaseObect is inherited from ManagementObject;

            foreach (ManagementBaseObject item in mObjSearch.Get())
            {
                textBox1.Text += //string.Concat("classPath", item.ClassPath.Path) + System.Environment.NewLine +
                    //string.Concat("ClassName", item.ClassPath.ClassName) +
                    System.Environment.NewLine + string.Concat("Name", item["Name"]).PadRight(5, ' ') +
                     string.Concat("Value", item["VariableValue"])
                     + System.Environment.NewLine;
            }
}
 
    Asynchronous way:
 ManagementObjectSearcher mObjSearch = new ManagementObjectSearcher(new SelectQuery("WIN32_Service"));
            ManagementOperationObserver mOperObserver = new ManagementOperationObserver();
            mOperObserver.ObjectReady += new ObjectReadyEventHandler(mOperObserver_ObjectReady);
            mOperObserver.Completed += new CompletedEventHandler(mOperObserver_Completed);
            mObjSearch.Get(mOperObserver);


本文转自lidup 51CTO博客,原文链接:http://blog.51cto.com/lidup/325289,如需转载请自行联系原作者

目录
打赏
0
0
0
0
69
分享
相关文章
电脑新装系统优化,win10优化,win10美化
电脑新装系统优化,win10优化,win10美化
99 4
邻接矩阵
数据结构中无向图邻接矩阵的存储
邻接矩阵
Python爬虫入门教程 31-100 36氪(36kr)数据抓取 scrapy
1. 36氪(36kr)数据----写在前面 今天抓取一个新闻媒体,36kr的文章内容,也是为后面的数据分析做相应的准备的,预计在12月底,爬虫大概写到50篇案例的时刻,将会迎来一个新的内容,系统的数据分析博文,记得关注哦~ 36kr 让一部分人先看到未来,而你今天要做的事情确实要抓取它的过去。
10427 0
提升铁路机务系统职工教育培训的有效对策
近年来,随着社会形势的不断变化和信息技术的发展,我国各行各业面临着很大的挑战,铁路机务系统也受到了很大的冲击。在这样的情况下,机务系统要想赢得生机和发展必须要加强内部管理和培训,提升企业职工的综合素质。做好铁路机务系统职工教育培训工作能够保证铁路机务系统的安全运输、生产稳定,对于促进铁路机务系统的可持续发展具有重要的意义。当前,随着铁路行业的发展,新设备、新技术、新工艺、新标准的广泛应用,社会对铁路机务系统职工教育培训工作提出了更多、更高的要求,为了进入适应社会形势的不断变化,必须要加强铁路机务系统职工教育培训工作,提升铁路人员的综合素质和服务能力。
艾伟:[WCF中的Binding模型]之一: Binding模型简介
1. 信道层与服务模型层(Channel Layer and Service Mode Layer) 对于一个分布式应用的开发与设计来说,通信问题是不得不考虑,同时也是最为复杂、最难实现的问题。在过去的若干年中, 微软先后推出了一系列广受欢迎的通信技术, 比如DCOM、Enterprise Service、.NET Remoting、XML Web Service、MSMQ等等。
1081 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问