Solved

How do you just return the hard drives on a pc

Posted on 2004-08-18
4
246 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 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

24 Experts available now in Live!

Get 1:1 Help Now