|
How To Get Hard Disk Information Using WMI
This article is a brief description of how you can use Windows Management
Instrumentation to get information about hard disks on your system. This
article does noe go into details of WMI. You can refer to Micorosft Platform SDK
for more information. But here we will show you can make use of System.Management
namespace classes in .Net framework to accomplish this task. The framework SDK
does not give details on all the properties and classes that are exposed by WMI
to accomplish various tasks. This article should get you started on usage of
WMI in .Net framework.
Hard disk information is exposed by Win32_DiskDrive WMI class.
This class exposes following properties to get information.
-
Availability
-
BytesPerSector
-
Capabilities
-
CapabilityDescriptions
-
Caption
-
CompressionMethod
-
ConfigManagerErrorCode
-
ConfigManagerUserConfig
-
CreationClassName
-
DefaultBlockSize
-
Description
-
DeviceID
-
ErrorCleared
-
ErrorDescription
-
ErrorMethodology
-
Index
-
InstallDate
-
InterfaceType
-
LastErrorCode
-
Manufacturer
-
MaxBlockSize
-
MaxMediaSize
-
MediaLoaded
-
MediaType
-
MinBlockSize
-
Model
-
Name
-
NeedsCleaning
-
NumberOfMediaSupported
-
Partitions
-
PNPDeviceID
-
PowerManagementCapabilities
-
PowerManagementSupported
-
SCSIBus
-
SCSILogicalUnit
-
SCSIPort
-
SCSITargetId
-
SectorsPerTrack
-
Signature
-
Size
-
Status
-
StatusInfo
-
SystemCreationClassName
-
SystemName
-
TotalCylinders
-
TotalHeads
-
TotalSectors
-
TotalTracks
-
TracksPerCylinder
using System;
using System.Management;
using System.Collections;
using System.Collections.Specialized;
namespace PardesiServices.WmiComponent
{
class WmiApp
{
[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]);
}
}
}
}
}
|