Using WMI to get information about your hard disk

Source: Internet
Author: User
Hard disk first, what is WMI?
WMI (Windows Management Schema: Windows Management Instrumentation) is a Microsoft web-based Enterprise Management (WBEM) and Desktop Management Task Force (DMTF) The realization of industrial standard. is a standards-based system Management development interface that is used to control the management of computers. It provides an easy way to manage and control system resources.
If you want to know more about him, you can refer to the micorosft Platform SDK. In this we just implement a simple function through it to get information about the hard disk in our system.
We need to implement the class provided in the. NET Framwork with the System.Management namespace.
Using System;
Using System.Management;
Using System.Collections;
Using System.Collections.Specialized;
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 has its own help with code to get the size of a logical hard disk:
[C #]

Using System;

Using System.Management;



This example demonstrates getting information about a class using the ManagementClass object

Class Sample_managementclass

{

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;

}

}


[VB]
Imports System

Imports System.Management



This example demonstrates getting information about a class using the ManagementClass

Class Sample_managementclass


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



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.