WMI should be able to handle this ...
You will need to add a link to the System.Management dll, and you will need: "using System.Management"; line ... See the link at the bottom for screenshots, a more detailed explanation ...
using System.Management; // Get all the disk drives ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); // Loop through each object (disk) retrieved by WMI foreach (ManagementObject moDisk in mosDisks.Get()) { // Add the HDD to the list (use the Model field as the item caption) cmbHdd.Items.Add(moDisk["Model"].ToString()); } private void cmbHdd_SelectedIndexChanged(object sender, EventArgs e) { // Get all the disk drives from WMI that match the Model name selected in the ComboBox ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Model = '" + cmbHdd.SelectedItem + "'"); // Loop through the drives retrieved, although it should normally be only one loop going on here foreach (ManagementObject moDisk in mosDisks.Get()) { // Set all the fields to the appropriate values lblType.Text = "Type: " + moDisk["MediaType"].ToString(); lblModel.Text = "Model: " + moDisk["Model"].ToString(); lblSerial.Text = "Serial: " + moDisk["SerialNumber"].ToString(); lblInterface.Text = "Interface: " + moDisk["InterfaceType"].ToString(); // The capacity in gigabytes is easily calculated lblCapacity.Text = "Capacity: " + moDisk["Size"].ToString() + " bytes (" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + " GB)"; lblPartitions.Text = "Partitions: " + moDisk["Partitions"].ToString(); lblSignature.Text = "Signature: " + moDisk["Signature"].ToString(); lblFirmware.Text = "Firmware: " + moDisk["FirmwareRevision"].ToString(); lblCylinders.Text = "Cylinders: " + moDisk["TotalCylinders"].ToString(); lblSectors.Text = "Sectors: " + moDisk["TotalSectors"].ToString(); lblHeads.Text = "Heads: " + moDisk["TotalHeads"].ToString(); lblTracks.Text = "Tracks: " + moDisk["TotalTracks"].ToString(); lblBytesPerSect.Text = "Bytes per Sector: " + moDisk["BytesPerSector"].ToString(); lblSectorsPerTrack.Text = "Sectors per Track: " + moDisk["SectorsPerTrack"].ToString(); lblTracksPerCyl.Text = "Tracks per Cylinder: " + moDisk["TracksPerCylinder"].ToString(); } }
From MSDN, the win32 class for CIM_DiskDrive has the following parameters:
* "DeviceID" seems to be what you want ...
class Win32_DiskDrive : CIM_DiskDrive { uint16 Availability; uint32 BytesPerSector; uint16 Capabilities[]; string CapabilityDescriptions[]; string Caption; string CompressionMethod; uint32 ConfigManagerErrorCode; boolean ConfigManagerUserConfig; string CreationClassName; uint64 DefaultBlockSize; string Description; string DeviceID; boolean ErrorCleared; string ErrorDescription; string ErrorMethodology; string FirmwareRevision; uint32 Index; datetime InstallDate; string InterfaceType; uint32 LastErrorCode; string Manufacturer; uint64 MaxBlockSize; uint64 MaxMediaSize; boolean MediaLoaded; string MediaType; uint64 MinBlockSize; string Model; string Name; boolean NeedsCleaning; uint32 NumberOfMediaSupported; uint32 Partitions; string PNPDeviceID; uint16 PowerManagementCapabilities[]; boolean PowerManagementSupported; uint32 SCSIBus; uint16 SCSILogicalUnit; uint16 SCSIPort; uint16 SCSITargetId; uint32 SectorsPerTrack; string SerialNumber; uint32 Signature; uint64 Size; string Status; uint16 StatusInfo; string SystemCreationClassName; string SystemName; uint64 TotalCylinders; uint32 TotalHeads; uint64 TotalSectors; uint64 TotalTracks; uint32 TracksPerCylinder; };
Top Portion oF Code taken from:
http://www.geekpedia.com/tutorial233_Getting-Disk-Drive-Information-using-WMI-and-Csharp.html
John bartels
source share