Link to home
Start Free TrialLog in
Avatar of kvnsdr
kvnsdr

asked on

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());
            }
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

@"Select * From Win32_PhysicalMedia Where Tag = \\.\PHYSICALDRIVE0"

Bob
Avatar of kvnsdr
kvnsdr

ASKER

Could not get yours to work.

This works for me: @"SELECT * FROM Win32_LogicalDisk where DeviceID = 'C:'");
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial