1. What is WMI?
WMI is short for Windows Management Instrumentation. Its function is mainly to access some information and services on the local host and manage remote computers (of course, you must have sufficient permissions ), for example, restart, shut down, shut down the process, and create a process.
2. How can I use WMI to obtain information about a local disk?
First, create a project in VS. NET, and then import a. net installation accessory: System. Management. dll in the Add reference so that your project can use WMI. The Code is as follows:
1 using System;
2 using System. Management;
3
4 class Sample_ManagementObject
5 {
6 public static int Main (string [] args)
7 {
8 SelectQuery query = new SelectQuery ("Select * From Win32_LogicalDisk ");
9 ManagementObjectSearcher searcher = new ManagementObjectSearcher (query );
10 foreach (ManagementBaseObject disk in searcher. Get ())
11 {
12Console. WriteLine ("" + disk ["Name"] + "" + disk ["DriveType"] + "" + disk ["VolumeName"]);
13}