Use WMI to get the hard disk information

zhaozj2021-02-16  71

First of all, what is WMI? WMI (Windows Management Architecture: Windows Management Instrument) is an implementation of Microsoft's Web-based Enterprise Management (WBEM) and Desktop Management Task Force (DMTF) industry standards. It is a standard-based system management development interface. This set of interfaces are used to control management computers. It provides a simple way to manage and control system resources. If you want to know more about him, you can refer to Micorosft Platform SDK. In this case, we just achieve a simple feature, Get relevant information about the hard drive in our system. We need to use the classes provided under the .NET FRAMWORK SYSTEM.MANAGEMENT name space.

Using system.management; using system.collections; using system.collections.specialize;

Namespace ace_console {class ace_console {[stathread] static void

Main

(String [] args) {StringCollection propNames = new StringCollection (); ManagementClass driveClass = new ManagementClass ( "Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) {propNames.Add (driveProperty.Name); }

int idx = 0; ManagementObjectCollection drives = driveClass.GetInstances (); foreach (ManagementObject drv in drives) {Console.WriteLine ( "Drive ({0}) Properties", idx 1); foreach (string strProp in propNames) {Console .Writeline ("Property: {0}, Value: {1}", Strprop, DRV [strprop]);}}}}}

The .NET Framework SDK comes with a logical hard disk size code:

[C #] using system;

Using system.management;

// this Example Demonstrate Getting Information About a class using the managementclass objectclass sample_managementClassClassClass Class

{

Public Static Int

Main

(String [] ARGS)

{

ManagementClass Diskclass = New ManagementClass ("Win32_LogicalDisk");

Diskclass.get ();

Console.writeline ("Logical Disk Class Has" DiskClass.Properties.count "Properties");

Return 0;

}

}

Imports system

Imports System.Management

// this Example Demonstrates Getting Information About a class using the managementclass

Class Sample_ManagementClassClassClassClass

Overloads Public Shared Function Main (args () as string AS Integer

DIM DISKCLASS AS New ManagementClass ("Win32_LogicalDisk")

Diskclass.get ()

Console.Writeline ("Logical Disk Class Has" & DiskClass.Properties.count.toString () & "Properties"))))

Return 0

END FUNCTION

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-25212.html

New Post(0)