Durgesh Pandey
Durgesh Pandey

Reputation: 2422

How to check hard disk is Sata Device or it is IDE Device using c#

I have SATA Hard Disk, and I want to detect by C# windows form. I want to display that it is SATA or IDE drive. I am using following code but it always return IDE but its should be return SATA. So any one can help me to where I am wrong.

WqlObjectQuery q = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive");
ManagementObjectSearcher res = new ManagementObjectSearcher(q);

foreach (ManagementObject o in res.Get())
 {
  string lblInterface= o["InterfaceType"].ToString();
 }

Upvotes: 7

Views: 1879

Answers (2)

nobody
nobody

Reputation: 11080

Check the caption property of win32_DiskDrive for the string ATA

From MSDN Caption Data type: string Access type: Read-only Qualifiers: MaxLen (64), DisplayName ("Caption") Short description of the object

foreach (ManagementObject o in res.Get())
{
     string sCaption = o["Caption"].ToString();
     if(sCaption.Contains("ATA"))
     {
          Console.WriteLine("SATA Drive");
          break;
     }
}

Upvotes: 1

Alex
Alex

Reputation: 987

According to the Win32_DiskDrive class documentation, the possible values for InterfaceType are:

SCSI

HDC

IDE

USB

1394

Hence, you would not see SATA.

However, Caption property may contain extra information about the drive. You can parse it to find whether it contains ATA or SCSI.

Upvotes: 1

Related Questions