Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gettings a List of Current Drives

Posted on 2006-07-10
6
Medium Priority
?
216 Views
Last Modified: 2010-04-23
I am using Visual Basic .NET. Is there a way to get a list of the current disk drives (CD-ROM included) on the specific system? For example: C:, D:, E:.. if they exist? Code would help. Thank you.
0
Comment
Question by:Linky
[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
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
concept99 earned 200 total points
ID: 17074687
Using WMI is probably your best bet in this situation. Here's the code:

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class MyWMIQuery

        Public Overloads Shared Function Main() As Integer

            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_LogicalDisk")

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_LogicalDisk instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Caption: {0}", queryObj("Caption"))
                    Console.WriteLine("Description: {0}", queryObj("Description"))
                    Console.WriteLine("FileSystem: {0}", queryObj("FileSystem"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace
0
 
LVL 2

Author Comment

by:Linky
ID: 17074713
There is no way to do with with DirectoryInfo or something?
0
 
LVL 41

Expert Comment

by:graye
ID: 17074750
The newer version of Visual Basic (version 2005) has the "My" namespace, so if you're using that version, it's as simple as:

For each DriveLetter as string in My.Computer.FileSystem.Drives
    ' do something
Next
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Expert Comment

by:graye
ID: 17074763
Oops, my example sucks

For each Drive As System.IO.DriveInfo in My.Computer.FileSystem.Drives
   ' do Something
Next
0
 
LVL 2

Author Comment

by:Linky
ID: 17074774
Im using 2002 so that probably won't work.
0
 
LVL 2

Author Comment

by:Linky
ID: 17075192
That does the trick in my program concept99. Thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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