Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do you just return the hard drives on a pc

Posted on 2004-08-18
4
Medium Priority
?
295 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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