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

drive types in VB.NET

P: n/a
Hi,

I am building an explorer type interface for file selection

Need to know how to determine what type of device a DRIVE is

i.e. C: (harddisk)

A: (floppy)

E: (cd-rom)

F: (zip)

h: (network)

etc.

I have found no such animal in .NET runtime.

Is there a managed way to do this? If not, how?

thanks,
Shane
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
Need to know how to determine what type of device a DRIVE is

i.e. C: (harddisk)

A: (floppy)

E: (cd-rom)

F: (zip)

h: (network)

etc.

I have found no such animal in .NET runtime.

Is there a managed way to do this? If not, how?


There is currently no managed way.

P/invoke:

'GetDriveType'

- or -

WMI:

<http://www.mvps.org/dotnet/dotnet/code/filesystem/>
-> "Laufwerke und ihren Typ ermitteln"

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
Addendum:
P/invoke:

'GetDriveType'


Sample:

<http://www.google.ch/groups?selm=OiKxMMizCHA.1776%40TK2MSFTNGP09>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
oddly enough I try this with INPUTBOX to test and keeps returning 1

no matter if I put in C:\
A:\
F:\

or whatever as the input string.

Is there a bug still?

1=== unknown.

Thanks,

Shane

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
Need to know how to determine what type of device a DRIVE is

i.e. C: (harddisk)

A: (floppy)

E: (cd-rom)

F: (zip)

h: (network)

etc.

I have found no such animal in .NET runtime.

Is there a managed way to do this? If not, how?


There is currently no managed way.

P/invoke:

'GetDriveType'

- or -

WMI:

<http://www.mvps.org/dotnet/dotnet/code/filesystem/>
-> "Laufwerke und ihren Typ ermitteln"

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

P: n/a
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
oddly enough I try this with INPUTBOX to test and keeps returning 1

no matter if I put in C:\
A:\
F:\

or whatever as the input string.

Is there a bug still?


Remove the backslash and try again.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a
Nope...

did this to test

Private Declare Auto Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Int32

Then my own enums.

Private Enum DriveTypes 'used with GetDriveType
Unknown = 0
Invalid_or_Not_Mounted=1 'invalid path: eg no volume mounted
Removable = 2
Fixed = 3
Remote = 4 'network
CDROM = 5
RAMDisk = 6
End Enum

Then in form_load, this quick testing code
Private Sub frmRestore_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim s As String = "a"
While s <> String.Empty
s = InputBox("Drive?", "prompt")
Dim iDriveType = GetDriveType(s)
'decide type of drive and display appropriate drive letter.
Select Case iDriveType
Case DriveTypes.CDROM
MsgBox("CD")
Case DriveTypes.Fixed
MsgBox("harddrive")
Case DriveTypes.Remote
MsgBox("network")
Case DriveTypes.Removable
If Char.ToUpper(s.Chars(0)) = "A" Or
Char.ToUpper(s.Chars(0)) = "B" Then 'ASSUME FLOPPY
MsgBox("floppy")
Else
MsgBox("zip")
End If
Case DriveTypes.RAMDisk
msgbox("ramdisk")
Case Else
MsgBox("other")
End Select
End While
End
End Sub

iDriveType is always 1 no matter what

A

A:\

A:

C

C:

C:\

doesn't work.

What am I doing wrong?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bu************@ID-208219.news.uni-berlin.de...
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
oddly enough I try this with INPUTBOX to test and keeps returning 1

no matter if I put in C:\
A:\
F:\

or whatever as the input string.

Is there a bug still?


Remove the backslash and try again.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #6

P: n/a
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> schrieb
iDriveType is always 1 no matter what

A

A:\

A:

C

C:

C:\

doesn't work.

What am I doing wrong?


Remove "Auto" from the declaraton. Then use "c:\". It works here.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

P: n/a
thanks.

that was it.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> schrieb
iDriveType is always 1 no matter what

A

A:\

A:

C

C:

C:\

doesn't work.

What am I doing wrong?


Remove "Auto" from the declaraton. Then use "c:\". It works here.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.