J
jimdscudder
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the
physical drive location index.
For example the following code will give me the physical drive location:
StringCollection propNames = new StringCollection();
ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
PropertyDataCollection props = driveClass.Properties;
foreach (PropertyData driveProperty in props)
{
propNames.Add(driveProperty.Name);
}
ManagementObjectCollection drives = driveClass.GetInstances();
foreach (ManagementObject drv in drives)
{
string id = "Index";
this.listBox1.Items.Add(" ******** Drive( " + drv[id].ToString() + " )
Location ************");
}
And, the follwoing code will give me the drive letter:
SelectQuery query = new SelectQuery( "select name, FreeSpace, SystemName
from win32_logicaldisk where drivetype=3" );
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get())
{
this.listBox1.Items.Add( "Drive letter is: " + mo["name"] );
}
How can I do a query using the drive location and get the drive letter
assigned to it?
physical drive location index.
For example the following code will give me the physical drive location:
StringCollection propNames = new StringCollection();
ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
PropertyDataCollection props = driveClass.Properties;
foreach (PropertyData driveProperty in props)
{
propNames.Add(driveProperty.Name);
}
ManagementObjectCollection drives = driveClass.GetInstances();
foreach (ManagementObject drv in drives)
{
string id = "Index";
this.listBox1.Items.Add(" ******** Drive( " + drv[id].ToString() + " )
Location ************");
}
And, the follwoing code will give me the drive letter:
SelectQuery query = new SelectQuery( "select name, FreeSpace, SystemName
from win32_logicaldisk where drivetype=3" );
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get())
{
this.listBox1.Items.Add( "Drive letter is: " + mo["name"] );
}
How can I do a query using the drive location and get the drive letter
assigned to it?