Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I am getting a drives type, (Removable Media, HDD, cd rom), and displaying it to the user.

 

Works great, but not on SP2, it returns a weird drive type (8975933078237085698)

 

It should return:

"9222812402616107010" = Check for Removable Media

"9222812402616107011" = Check For HardDisks

"9222812402616107013" = 'Check for Cd-Roms

 

But as you can see not even close.

 

Below is the code, anyone know why this is an issue????????

 

 

 

   Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

       Dim strDrives As String() = Environment.GetLogicalDrives()
       Dim drive As String
       For Each drive In strDrives
           Dim strType As String = GetDriveType(drive)
           Dim driveSTR As String = "Unknown Type : "

           TextBox1.Text &= (drive & " is type : ")

           Select Case strType
               Case "9222812402616107010"
                   'Check for Removable Media
                   driveSTR = "Removable Media"
               Case "9222812402616107011"
                   'Check For HardDisks
                   driveSTR = "Hard Disc"
               Case "9222812402616107013"
                   'Check for Cd-Roms
                   driveSTR = "CD-ROM"
               Case Else
                   driveSTR &= strType
           End Select
           TextBox1.Text &= driveSTR & vbCrLf
       Next

  • Administrators
Posted

You could use the System.Management namespace instead like

Dim diskClass As New ManagementClass("Win32_LogicalDisk")
       Dim disks As ManagementObjectCollection = diskClass.GetInstances()
       Dim disksEnumerator As _
       ManagementObjectCollection.ManagementObjectEnumerator = _
       disks.GetEnumerator()
       While disksEnumerator.MoveNext()
           Dim disk As ManagementObject = _
           DirectCast(disksEnumerator.Current, ManagementObject)

           'Drive letter is the caption, message is the type where
           'NoRoot = 1, Removable = 2, LocalDisk = 3, Network = 4,CD = 5, RAMDrive = 6
           MessageBox.Show(disk("DriveType").ToString, disk("deviceid").ToString)
       End While

 

or alternatively change the declaration to

Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Integer

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Thanks!

 

Thankyou,

 

I used a base of your code to end up with the following, which gives me everything:

 

Hello,

 

       TextBox1.Text = ""
       Dim diskClass As New ManagementClass("Win32_LogicalDisk")
       Dim disks As ManagementObjectCollection = diskClass.GetInstances()
       Dim disksEnumerator As ManagementObjectCollection.ManagementObjectEnumerator = disks.GetEnumerator()
       While disksEnumerator.MoveNext()
           Dim disk As ManagementObject = DirectCast(disksEnumerator.Current, ManagementObject)

           Dim propNames As StringCollection = New StringCollection
           Dim props As PropertyDataCollection = diskClass.Properties

           For Each driveProperty As PropertyData In props
               propNames.Add(driveProperty.Name)
           Next

           TextBox1.Text &= " Drive " & disk("deviceid").ToString & "\ Properties: " & vbCrLf

           Dim idx As Int16 = 0

           For Each strProp As String In propNames
               If Not disk(strProp) Is Nothing Then
                   TextBox1.Text &= strProp & ": " & disk(strProp).ToString
               Else
                   TextBox1.Text &= strProp & ": NOTHING"
               End If
               TextBox1.Text &= vbCrLf
           Next
           TextBox1.Text &= vbCrLf & vbCrLf

       End While

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...