Getting started with WMI (II): How to Use WMI

Source: Internet
Author: User
ArticleDirectory
    • WMI Tool
    • Script WMI operation
    • . Net Operation WMI
    • Conclusion

After knowing what WMI is, you must know how to Use WMI. Can it write "Hello World? WMI is not that boring. As soon as it comes up, it will ask you "what do you want ?" Or "what do you want to change ?"...

WMI Tool

Windows provides several wmitool for users, including wmic.exe1_wbemtest.exe and WMI administrative tools. The first two are provided by the system, and the last one needs to be downloaded and installed by yourself. But to be honest, I like WMI Administrative Tools best. Download WMI administrative tools here. The following uses WMI administrative tools as an example to describe how to use WMI.

After downloading and installing WMI Administrative Tools, there will be four tools, the most common of which is wmi cim studio. Click it in the Start menu and you will find that it is opened in IE browser as a webpage.

The procedure is as follows:

1. Click the computer icon in the upper part of the page. A dialog box is displayed. Click Connect, as shown in 1;

Figure 1

2. The Login Dialog Box shown in 2 appears at any time. Click OK;

Figure 2

3. Select the appropriate command space (usually Root \ cimv2) and click OK, as shown in figure 3;

Figure 3

4. Double-click the class name on the right or click the telescope button on the top. In the pop-up dialog box, enter the complete class name or part of the class name you want to search, click Go To search. In the search result, select the class name you want to view and click OK, as shown in figure 4;

Figure 4

5. Click the last 4th instances in the upper right corner to obtain the list of software installed on the local machine, as shown in Figure 5;

Figure 5

You can refer to the above steps to view any WMI class and instance.

Script WMI operation

In the past, WMI operations were performed through VB script. Now more people prefer to use powershell to access WMI classes and objects. The following example shows how to use the powershell command to query the list of all software installed on the local machine:

PS c: \ Users \ Luke> Get-wmiobject-class win32_product |Select namename----Helploud Windows Installer clean upxml notepad2007Microsoft Network Monitor3.4Microsoft Visual Studio2010 Service Pack 1Screenrecordermicrosoft office Visual Web Developer2007Microsoft Office Visual Web Developer Mui (English)2007...

It is much simpler than WMI with interface, and there are many filtering conditions.

. Net Operation WMI

It is also very convenient to use the advanced language in. Net to operate WMI. The following example demonstrates how to operate WMI to obtain the list of software installed on the local machine.Code:

 Using  System;  Using System. Management;  Namespace  Wmidemo {  Class  Program {  Static   Void Main ( String  [] ARGs) {managementpath wmipath = New Managementpath ( @"  \. \ Root \ cimv2: win32_product  "  ); Managementclass wmiclass = New  Managementclass (wmipath); managementobjectcollection instances = Wmiclass. getinstances (); console. writeline (  "  Name, vendor  "  );  Foreach (Managementobject Product In  Instances) {console. writeline (string. Format (  "  {0}, {1}  " , Product [ "  Name  " ], Product [ "  Vendor  "  ]) ;}}} 
Conclusion

WMI is a versatile operator that you can use from various test surfaces. Apply an advertisement word: How do you use WMI?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.