Drive Type in VB.Net

  • Thread starter Thread starter Hardik Shah
  • Start date Start date
H

Hardik Shah

Hi,

I want to know systems drive type i.e. CD Writer, Zip, Floppy.
Through Environment.GetLogicalDrive , I can know only name of drive letter .

How Can I,

Thanks in advance.

Hardik Shah
 
Hardik,

\\\Made by Herfried K. Wagner
Set a reference to System.Management.dll
Imports System.Management
..
..
..
Public Enum DriveType
Unknown = 0
NoRootDirectory = 1
RemoveableDisk = 2
LocalDisk = 3
NetworkDrive = 4
CompactDisk = 5
RamDisk = 6
End Enum

Public Function GetDriveType(ByVal strDrive As String) As DriveType
strDrive = "Win32_LogicalDisk='" & strDrive.Substring(0, 2) & "'"
Dim moDisk As ManagementObject = New ManagementObject(strDrive)
Return _
DirectCast( _
[Enum].Parse(GetType(DriveType),
moDisk("DriveType").ToString()), _
DriveType _
)
End Function
..
..
..
Dim astrDrives() As String = Environment.GetLogicalDrives()
Dim strDrive As String
For Each strDrive In astrDrives
MessageBox.Show( _
"Drive: " & strDrive & ControlChars.NewLine & _
"Type: " & GetDriveType(strDrive).ToString() _
)
Next strDrive
///


I hope this helps a little bit?

Cor
 
Hardik Shah said:
I want to know systems drive type i.e. CD Writer, Zip, Floppy.
Through Environment.GetLogicalDrive , I can know only name of drive letter
.

I recommend to use p/invoke and the 'GetDriveType' function in .NET 1.0/1.1:

<URL:http://dotnet.mvps.org/dotnet/faqs/?id=setcddoorstatus&lang=en>

Alternatively you can use WMI. However, note that this may be slower than
'GetDriveType' and that WMI must be installed on the machine:

<URL:http://dotnet.mvps.org/dotnet/code/filesystem/#DriveType>

..NET 2.0 will contain the class 'System.IO.DriveInfo' which has a property
'DriveType'.
 
Back
Top