By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

Drive Type in VB.Net

P: n/a
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


Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Nov 21 '05 #2

P: n/a
"Hardik Shah" <ha********@hotmail.com> schrieb:
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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.