473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

drive types in VB.NET

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
7 2054
* "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
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
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
* "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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: GregT | last post by:
I program in C#. Is there a way to determine which of the local machine's logical drives are associated with CD drive(s)?
2
by: DBLWizard | last post by:
Howdy All, I have been looking and am amazed that there is not an equivilent object as the WSH or FSO in .net. To be able to get Drive information you either have to use COM on one of the two...
3
by: Nathaniel Wingard | last post by:
I recently was asked to write a program that moved files to certain places on a network drive based on what the files were (mainly filenames since the files are mostly Office documents of various...
2
by: Al Sav | last post by:
Hi, After enumerating the logical drives, using GetLogicalDrives, I need to know the Drive Types, ie. Floppy or Network. Is it possible in C# to do this? Thanks in advance. Alwin S.
6
by: Matthias Heise | last post by:
Hello, I just got my drives through Directory.GetLogicalDrives() but now I want to distinguesh between real harddisk, floppy, CD-Rom or network drive. I didn't find any good idea for that. ...
12
by: greg_chu | last post by:
Hi, I know I can use ipconfig.exe is DOS to get my IP address, the situation is I need to automat this process. I need to write a DOS program which issue a command to run IPCONFIG to get the IP...
1
by: shailesh | last post by:
Hi, Few very simple questions. Is there a way to detect whether a drive is a mapped network drive or not in Windows? Also, how can I get a list of drive letters currently in use in the...
23
by: Rotsey | last post by:
Hi, I am writing an app that scans hard drives and logs info about every fine on the drive. The first iteration of my code used a class and a generic list to store the data and rhis took...
1
9815402440
by: 9815402440 | last post by:
hi about a month ago a guy posted this question (how to know that selected drive is removable or cd rom) this is how i did it. Dim d As Drive Dim fs As New FileSystemObject Set...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.