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,如需转载请自行联系原作者

相关文章
|
Oracle 关系型数据库 Unix
|
安全
Information Systems Security Assessment – Open information security framework
The Information Systems Security Assessment Framework (ISSAF) seeks to integrate the following m...
988 0
|
SQL 缓存 算法
Access Path Selection in a Relational Database Management System
如果说选一篇在优化器框架上,被引用次数最多的文献,应该非这篇论文莫属了,还记得Andy Pavlo在cmu的课程中提到IBM Research的一群大神们,是怎么一人一个模块来负责System R的设计的,而关于Join order enumeration,Selinger可以说是开创了dynamic programing based 的bottom-up的搜索空间算法的先河,直至今日,很多成熟的商业或开源数据库系统仍在沿用这套框架,比如Oracle / DB2 / PostgreSQL ...
619 0
Access Path Selection in a Relational Database Management System
|
SQL 固态存储 OLAP
Alibaba Cloud Database group's Academic programs and Recruitment information
We are hiring technical experts   Database Kernel Expert: Job Description: Alibaba Cloud ApsaraDB team is well known for database products, includi.
2008 0
|
安全
Network and Distributed System Security (NDSS) Symposium 2017
https://www.youtube.com/playlist?list=PLfUWWM-POgQsZ9YCXLaCHIvn_H6-F4esJ ...
921 0
Common mistakes to avoid while using big data in risk management
Managing risk is a challenging enterprise, and errors are often made which can lead to catastrophic consequences.
1675 0
|
安全
Magic Quadrant for Security Information and Event Management 2015
http://www.gartner.com/technology/reprints.do?id=1-2J31FF4&ct=150706&st=sb ...
691 0