Solved

How do you just return the hard drives on a pc

Posted on 2004-08-18
4
228 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
4 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 200 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 200 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now