Knowing what WMI is, you definitely want to know how to work with WMI. Can it write "Hello world"? WMI isn't that boring, and it's going to ask you "What do you want?" "or" What do you want to change? ”。。。
WMI Tools
Windows itself provides several WMI tools for users to use, including WMIC.exe, WBEMTest.exe, and WMI Administrative tools. The first two are the system itself, the last one to download the installation itself. But to tell you the truth, I like WMI administrative Tools best. Download WMI Administrative Tools here. The following is an example of WMI administrative tools to illustrate how to use the tool to use WMI.
After you download and install WMI Administrative Tools, there are 4 tools, most commonly used by WMI CIM Studio. Click on it in the Start menu, and you'll find it opens in Internet Explorer as a Web page.
Use the following steps:
1, click on the top of the computer icon, will display a dialog box, click the "Connect" button, as shown in Figure 1;
Figure 1
2, any time appear as shown in Figure 2 Login dialog box, click OK button;
Figure 2
3, select the appropriate command space (here to select the common root\cimv2), and then click the OK button, as shown in Figure 3;
Figure 3
4, directly double-click the right class name, or click the upper Telescope button, enter the full class name or part of the class name you want to find in the pop-up Lookup dialog, click the Go button, and select the class name you want to view in the search results, click the OK button, as shown in Figure 4;
Figure 4
5, click the bottom right Top 4th instance button, you can get all the installed software list, as shown in Figure 5;
Figure 5
Any WMI class and the view of an instance can refer to the above steps.
PowerShell Script Operations WMI
Previous operations on WMI were performed through VB Script, and more people now tend to use PowerShell to access WMI classes and objects. The following is an example of using the PowerShell command to query for a list of all the software installed on this computer:
Copy Code code as follows:
PS c:\users\luke> Get-wmiobject-class Win32_Product | Select Name
Name
----
HelpDesk
Windows Installer Clean Up
XML Notepad 2007
Microsoft Network Monitor 3.4
Microsoft Visual Studio Service Pack 1
Screenrecorder
Microsoft Office Visual Web Developer 2007
Microsoft Office Visual Web Developer MUI (中文版) 2007
...
It's much simpler than using WMI with interfaces, and you can have a lot of filtering criteria.
. NET Operations WMI
Use. NET is also very handy for manipulating WMI in a high-level language. The following example shows code for C # operations WMI obtaining a list of native installation software:
Copy Code code as follows:
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 person, and you can use it from each measurement surface. What do you do with a word of an ad: about WMI?