Results 1 to 4 of 4

Thread: Get list of local drives on PC

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Get list of local drives on PC

    I have the following code that gets a list of logical drives on a PC

    Dim driveArray() As String

    driveArray = System.IO.Directory.GetLogicalDrives

    Dim en As System.Collections.IEnumerator
    en = driveArray.GetEnumerator

    Problem is, this also returns mapped network drives, how can I get a list of only local drives on a PC?

    Thanks

  2. #2
    Member
    Join Date
    Aug 2003
    Posts
    51
    VB Code:
    1. Dim driveArray() As String = System.IO.Directory.GetLogicalDrives
    2.         For i As Integer = 0 To UBound(driveArray)
    3.             TextBox1.Text += driveArray(i) & vbCrLf
    4.         Next i

  3. #3

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    How does this help me?

    This will also display mapped network drives

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    VB Code:
    1. Public Sub ShowDrives()
    2.         ' Show all  drives on the local system.
    3.         ' Uses System.Management, so you need to create a reference in your project
    4.        
    5.         Const NoRoot As Integer = 1
    6.         Const Removable As Integer = 2
    7.         Const LocalDisk As Integer = 3
    8.         Const Network As Integer = 4
    9.         Const CD As Integer = 5
    10.         Const RAMDrive As Integer = 6
    11.  
    12.         Dim Scope As ManagementScope = New ManagementScope(ManagementPath.DefaultPath)
    13.         Dim Query As New SelectQuery("Win32_LogicalDisk")
    14.         Dim Searcher As New ManagementObjectSearcher(Scope, Query)
    15.         Dim Iterator As ManagementObject
    16.  
    17.         For Each Iterator In Searcher.Get()
    18.             If Iterator.Item("DriveType").ToString = LocalDisk.ToString Then
    19.                 Console.WriteLine( _
    20.                     "Found Local Drive, drive letter: " & _
    21.                     Iterator.Item("DeviceID").ToString & "(" & _
    22.                     Iterator.Item("Description").ToString & ")")
    23.             End If
    24.         Next
    25.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width