2

I'm doing a couple WMI queries to get information regarding the hard drives on a computer, specifically I'm using the namespaces Win32_DiskDrive, to get general hard drive information and MSStorageDriver_ATAPISmartData, to get SMART data.

My queries are as follows:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject wmiValue in searcher.Get())
{
    hd.Model = wmiValue["Model"].ToString().Trim();
    ...
}

And like this:

searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
foreach (ManagementObject wmiValue in searcher.Get())
{
    hd.InstanceName = wmiValue["InstanceName"].ToString().Trim();
    ...
}

The problem is that for some reason I get the results in different order, such as this:

Win32_DiskDrive query:

  • Value A for Disk 1
  • Value B for Disk 1
  • ...
  • Value A for Disk 2
  • ...

MSStorageDriver_ATAPISmartData query:

  • Value A for Disk 2
  • Value B for Disk 2
  • ...
  • Value A for Disk 1
  • ...

Now I only have 2 hard drives on my computer, so I don't really know if this will always be the case, or if it´s just something in particular in my system that forces the results of the queries to be sorted differently.

The MSStorageDriver_ATAPISmartData namespace does include the InstanceName value which should include the Model of the hard drive which could potentially be used to link that information with the information from the previous query, however that data is not exactly the same as in the Win32_DiskDrive query, as it separates the brand and apparently has a character limit, not to mention you could have 2 hard drives of the same model on your computer.

I'm also using the Name value from the Win32_DiskDrive namespace and the values it returns are as follows:

Disk 1: \\.\PHYSICALDRIVE1
Disk 2: \\.\PHYSICALDRIVE0

So is this behaviour normal, should I just trust it will always be 1, 2, ... and ..., 2, 1, and make the data match in the application, or is there another way to fix this?

user1676874
  • 875
  • 2
  • 24
  • 45

0 Answers0