?
Solved

How do you just return the hard drives on a pc

Posted on 2004-08-18
4
Medium Priority
?
288 Views
Last Modified: 2010-04-23
Hello I’m trying to get a list of all the local hard drives on a pc for an application.
I’m currently using       System.IO.Directory.GetLogticalDrives

This works really well but returns things like the floppy drive, cd drive, network drives and flash sticks. Is there a way to just get the local hard drives returned.

Thanks
0
Comment
Question by:FRIBBLE1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 800 total points
ID: 11829610
Sub GetLocalDrives()
      ' Use the System.Management classes to invoke WMI
      ' to get a list of local drives
      '
      ListView1.Items.Clear()
      
      Dim MyQuery As Management.ManagementObjectSearcher = New Management.ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
      Dim MyQueryResults As Management.ManagementObjectCollection = MyQuery.Get()
      Dim tmpItem As New ListViewItem()
      
      Dim MyObject As Management.ManagementObject

      For Each MyObject In MyQueryResults
          tmpItem = ListView1.Items.Add(MyObject.ToString.Trim)
          tmpItem.SubItems.Add(MyObject.Item("DriveType").ToString())
      Next

End Sub
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 800 total points
ID: 11830403
Imports System.IO

Public Function ListAllDrives() As String()
        Dim arDrives() As String
        arDrives = Directory.GetLogicalDrives()
        Return arDrives
End Function

'SAMPLE USAGE
        Dim sDrive As String, sDrives() As String
        sDrives = ListAllDrives()
        For Each sDrive In sDrives
            Debug.WriteLine(sDrive)
        Next

And for Drive volumes:

Public Declare Function GetVolumeSerialNumber Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As Long, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Long, ByVal lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As Long, ByVal nFileSystemNameSize As Long) As Long

Public Function VolumeSerial(DriveLetter) As Long
    Dim Serial As Long
    Call GetVolumeSerialNumber(UCase(DriveLetter) & ":\", 0&, 0&, Serial, 0&, 0&, 0&, 0&)
    VolumeSerial = Serial
End Function

 
Example Usage

MsgBox VolumeSerial("C")

Regards,

Aeros
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question