drive types in VB.NET

  • Thread starter Thread starter SStory
  • Start date Start date
S

SStory

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
 
* "SStory said:
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"
 
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
 
* "SStory said:
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.
 
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?
 
SStory said:
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.
 
Back
Top