{"id":6038,"date":"2014-04-12T02:53:19","date_gmt":"2014-04-12T02:53:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/12\/wmi-to-get-drive-letter-association-with-physical-drive-path-misses-cdroms-collection-of-common-programming-errors-2\/"},"modified":"2014-04-12T02:53:19","modified_gmt":"2014-04-12T02:53:19","slug":"wmi-to-get-drive-letter-association-with-physical-drive-path-misses-cdroms-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/12\/wmi-to-get-drive-letter-association-with-physical-drive-path-misses-cdroms-collection-of-common-programming-errors-2\/","title":{"rendered":"WMI to get drive letter association with physical drive path, misses CDROMs-Collection of common programming errors"},"content":{"rendered":"<p>I think you wouldn need to use the <code>Win32_CDROMDrive<\/code> WMI class to access CD-ROM info. The code you have above is looking for physical drives in the <code>Win32_DiskDrive<\/code> class, it excludes CD_ROM<\/p>\n<p>You could additional lines to get similar data &#8211; but not the same given CD-ROMs don&#8217;t have the Partition characteristics that your current code does<\/p>\n<pre><code>ComputerName = \".\"\nSet wmiServices = GetObject _\n                  (\"winmgmts:{impersonationLevel=Impersonate}!\/\/\" &amp; ComputerName)\nSet wmiDiskDrives = wmiServices.ExecQuery _\n                    (\"SELECT * FROM Win32_CDROMDrive\")\nFor Each wmiDiskDrive In wmiDiskDrives\n    MsgBox wmiDiskDrive.drive &amp; \"=\" &amp; wmiDiskDrive.DeviceID\nNext\n<\/code><\/pre>\n<p>Instead I think this different VBS <em>may<\/em> do what you want &#8211; the may part as I dont think the partition info is relevant to you.<\/p>\n<p><strong>vbs version<\/strong><\/p>\n<pre><code>Dim objFSO\nDim colDrives\nDim strOut\nDim strArray\n\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nstrArray = Array(\"Unknown\", \"Removable\", \"Fixed\", \"Network\", \"CD-ROM\", \"RAM Disk\")\nOn Error Resume Next\n'File system errors for virtual drives\nFor Each objDrive In colDrives\n    strOut = \"Drive letter: \" &amp; objDrive.DriveLetter &amp; vbNewLine\n    strOut = strOut &amp; (\"Drive type: \" &amp; strArray(objDrive.DriveType) &amp; vbNewLine)\n    strOut = strOut &amp; (\"File system: \" &amp; objDrive.FileSystem &amp; vbNewLine)\n    strOut = strOut &amp; (\"Path: \" &amp; objDrive.Path)\n    wscript.echo strOut\nNext\nOn Error GoTo 0\n<\/code><\/pre>\n<p><strong>vba version<\/strong><\/p>\n<pre><code>Sub Test()\nDim objFSO As Object\nDim colDrives As Object\nDim strOut As String\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nOn Error Resume Next\n'File system errors for virtual drives\nFor Each objDrive In colDrives\n    strOut = \"Drive letter: \" &amp; objDrive.DriveLetter &amp; vbNewLine\n    strOut = strOut &amp; (\"Drive type: \" &amp; Choose(objDrive.DriveType + 1, \"Unknown\", \"Removable\", \"Fixed\", \"Network\", \"CD-ROM\", \"RAM Disk\") &amp; vbNewLine)\n    strOut = strOut &amp; (\"File system: \" &amp; objDrive.FileSystem &amp; vbNewLine)\n    strOut = strOut &amp; (\"Path: \" &amp; objDrive.Path)\n    MsgBox strOut\nNext\nOn Error GoTo 0\nEnd Sub\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I think you wouldn need to use the Win32_CDROMDrive WMI class to access CD-ROM info. The code you have above is looking for physical drives in the Win32_DiskDrive class, it excludes CD_ROM You could additional lines to get similar data &#8211; but not the same given CD-ROMs don&#8217;t have the Partition characteristics that your current [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6038","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6038"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6038\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}