Problem to use letters ( c: , d:) with the physical drive:
-
Hi I'm trying to use the name of a logical drive (c: and d:). I can't use them to get access to the physical drive in order to get the type, the model, the interface, the capacity, sectors and cylinders. My code : private void Form1_Load(object sender, EventArgs e) { ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk"); foreach (ManagementObject moDisk in mosDisks.Get()) { comboBox2.Items.Add(moDisk["DeviceID"].ToString()); } } private void button4_Click_1(object sender, EventArgs e) { listView2.Items.Clear() ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE DeviceID = '" + comboBox2.SelectedItem + "'"); foreach (ManagementObject moDisk in mosDisks.Get()) { ListViewItem item = listView2.Items.Add("Type: " + moDisk["MediaType"].ToString()); ListViewItem item2 = listView2.Items.Add("Model: " + moDisk["Model"].ToString()); ListViewItem item3 = listView2.Items.Add("Interface: " + moDisk["InterfaceType"].ToString()); ListViewItem item4 = listView2.Items.Add("Capacity: " + moDisk["Size"].ToString() + " bytes (" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + " GB)"); ListViewItem item5 = listView2.Items.Add("Partitions: " + moDisk["Partitions"].ToString()); ListViewItem item6 = listView2.Items.Add("Signature: " + moDisk["Signature"].ToString()); ListViewItem item7 = listView2.Items.Add("Cylinders: " + moDisk["TotalCylinders"].ToString()); ListViewItem item8 = listView2.Items.Add("Sectors: " + moDisk["TotalSectors"].ToString()); ListViewItem item9 = listView2.Items.Add("Heads: " + moDisk["TotalHeads"].ToString()); ListViewItem item10 = listView2.Items.Add("Tracks: " + moDisk["TotalTracks"].ToString()); ListViewItem item11 = listView2.Items.Add("Bytes per Sector: " + moDisk["BytesPerSector"].ToString()); ListViewItem item12 = listView2.Items.Add("Sectors per Track: " + moDisk["SectorsPerTrack"].ToString()); ListViewItem item13 = listView2.Items.Add("Tracks per Cylinder: " + moDisk["TracksPerCylinder"].ToString()); ListViewItem item14 = listView2.Items.Add("Description: " + moDisk["Desc
-
Hi I'm trying to use the name of a logical drive (c: and d:). I can't use them to get access to the physical drive in order to get the type, the model, the interface, the capacity, sectors and cylinders. My code : private void Form1_Load(object sender, EventArgs e) { ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk"); foreach (ManagementObject moDisk in mosDisks.Get()) { comboBox2.Items.Add(moDisk["DeviceID"].ToString()); } } private void button4_Click_1(object sender, EventArgs e) { listView2.Items.Clear() ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE DeviceID = '" + comboBox2.SelectedItem + "'"); foreach (ManagementObject moDisk in mosDisks.Get()) { ListViewItem item = listView2.Items.Add("Type: " + moDisk["MediaType"].ToString()); ListViewItem item2 = listView2.Items.Add("Model: " + moDisk["Model"].ToString()); ListViewItem item3 = listView2.Items.Add("Interface: " + moDisk["InterfaceType"].ToString()); ListViewItem item4 = listView2.Items.Add("Capacity: " + moDisk["Size"].ToString() + " bytes (" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + " GB)"); ListViewItem item5 = listView2.Items.Add("Partitions: " + moDisk["Partitions"].ToString()); ListViewItem item6 = listView2.Items.Add("Signature: " + moDisk["Signature"].ToString()); ListViewItem item7 = listView2.Items.Add("Cylinders: " + moDisk["TotalCylinders"].ToString()); ListViewItem item8 = listView2.Items.Add("Sectors: " + moDisk["TotalSectors"].ToString()); ListViewItem item9 = listView2.Items.Add("Heads: " + moDisk["TotalHeads"].ToString()); ListViewItem item10 = listView2.Items.Add("Tracks: " + moDisk["TotalTracks"].ToString()); ListViewItem item11 = listView2.Items.Add("Bytes per Sector: " + moDisk["BytesPerSector"].ToString()); ListViewItem item12 = listView2.Items.Add("Sectors per Track: " + moDisk["SectorsPerTrack"].ToString()); ListViewItem item13 = listView2.Items.Add("Tracks per Cylinder: " + moDisk["TracksPerCylinder"].ToString()); ListViewItem item14 = listView2.Items.Add("Description: " + moDisk["Desc
I am not sure that you can get the drive letters using the PhysicalDrive. Look up
Win32_MappedLogicalDisk
in the WMI documentation. From memory it is much easier to get the drive letters that way.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec. Business Myths of the Geek #4 'What you think matters.'
-
Hi I'm trying to use the name of a logical drive (c: and d:). I can't use them to get access to the physical drive in order to get the type, the model, the interface, the capacity, sectors and cylinders. My code : private void Form1_Load(object sender, EventArgs e) { ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk"); foreach (ManagementObject moDisk in mosDisks.Get()) { comboBox2.Items.Add(moDisk["DeviceID"].ToString()); } } private void button4_Click_1(object sender, EventArgs e) { listView2.Items.Clear() ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE DeviceID = '" + comboBox2.SelectedItem + "'"); foreach (ManagementObject moDisk in mosDisks.Get()) { ListViewItem item = listView2.Items.Add("Type: " + moDisk["MediaType"].ToString()); ListViewItem item2 = listView2.Items.Add("Model: " + moDisk["Model"].ToString()); ListViewItem item3 = listView2.Items.Add("Interface: " + moDisk["InterfaceType"].ToString()); ListViewItem item4 = listView2.Items.Add("Capacity: " + moDisk["Size"].ToString() + " bytes (" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + " GB)"); ListViewItem item5 = listView2.Items.Add("Partitions: " + moDisk["Partitions"].ToString()); ListViewItem item6 = listView2.Items.Add("Signature: " + moDisk["Signature"].ToString()); ListViewItem item7 = listView2.Items.Add("Cylinders: " + moDisk["TotalCylinders"].ToString()); ListViewItem item8 = listView2.Items.Add("Sectors: " + moDisk["TotalSectors"].ToString()); ListViewItem item9 = listView2.Items.Add("Heads: " + moDisk["TotalHeads"].ToString()); ListViewItem item10 = listView2.Items.Add("Tracks: " + moDisk["TotalTracks"].ToString()); ListViewItem item11 = listView2.Items.Add("Bytes per Sector: " + moDisk["BytesPerSector"].ToString()); ListViewItem item12 = listView2.Items.Add("Sectors per Track: " + moDisk["SectorsPerTrack"].ToString()); ListViewItem item13 = listView2.Items.Add("Tracks per Cylinder: " + moDisk["TracksPerCylinder"].ToString()); ListViewItem item14 = listView2.Items.Add("Description: " + moDisk["Desc
The logical drives (drive letters) identify partitions, not physical devices. It takes a couple of WMI objects to get most of the information you want; you will probably discover that the very physical characteristics (such as number of cylinders) don't make sense any more as they are virtualized within the drive itself; the local intelligence just makes the disk look like one heap of sectors. Also, the latest versions of Windows (Vista, 7) are likely to refuse full access, even read access, at the device level unless you are an elevated escalated super-administrator. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
The Lion has roared