ManagementClass Get First Harddrive Only?

I'm working with the following typical example of WMI hardware searching, but only need the FIRST harddrive instead of the whole array. The following code is all I can find.

ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
            foreach (ManagementObject mo in mc.GetInstances())
            {
                if (mo["SerialNumber"] != null)
                    data.DriveSerialNumbers.Add(mo["SerialNumber"].ToString());
            }
LVL 1
kvnsdrAsked:
Who is Participating?
 
GranModConnect With a Mentor Commented:
Closed, 250 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
Bob LearnedCommented:
@"Select * From Win32_PhysicalMedia Where Tag = \\.\PHYSICALDRIVE0"

Bob
0
 
kvnsdrAuthor Commented:
Could not get yours to work.

This works for me: @"SELECT * FROM Win32_LogicalDisk where DeviceID = 'C:'");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.