Click to See Complete Forum and Search --> : Finding Physical Drive Number using Drive Letter


gmorris04
June 16th, 2009, 11:12 AM
HI,
I am new to VB.NET and I hope someone here can help me.

I have a program that allows the user to enter a drive letter into a text box. The program then takes the letter and find the physical drive number (i.e. \device\harddisk3\..). It then stripes out everything and leaves me with the number 3.

In VB6 I used mDrive.bas from vbAccelerator.com and it worked perfectly. I have been all over the internet and back and cannot find a solution written in VB.NET.

Any help would be greatly appreciated.

dglienna
June 16th, 2009, 09:02 PM
Went thru 4 of your posts (I'd guess) and then found this one. Google is your friend!

http://vbnet.mvps.org/index.html?code/disk/deviodriveinfo.htm

(not allowed to post it anyways)

gmorris04
June 17th, 2009, 06:18 AM
Thanks dglienna, but this is for VB6. I have been all over their site and used one of their code snipits in my VB6 program. Unfortunately it doesn't work with VB.Net. I have seen quite a bit of activity spanning through the years asking my very same question but no solid solutions. I will post my solution once I get one.

dglienna
June 18th, 2009, 12:25 AM
Well, who do you think WROTE the Windows API's that you are looking for?
Always look at MSDN. Here's how to add kernal32 to vb.net


[DllImport("kernel32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _Public Shared Function GetLogicalDrives() As IntegerEnd Function

HanneSThEGreaT
June 19th, 2009, 09:07 AM
No need for API :)

All you need is the System.IO namespace, and use a DriveInfo object, as shown with these examples :

http://www.java2s.com/Code/VB/File-Directory/DisplayDriveInfoDriveLetter.htm

dglienna
June 19th, 2009, 06:27 PM
He wants:

(i.e. \device\harddisk3\..). It

And I doubt that's the order that gets called, but I could be wrong. Where do you see the disk number? I don't see one in Vista

HanneSThEGreaT
June 20th, 2009, 05:01 AM
Then, he'd still need the System.IO namespace ( to determine how many drives etc. are on the pc ), the rest can be done using basic String Manipulation.. :)

dglienna
June 20th, 2009, 02:17 PM
I wasn't asking you, Hannes. :)

HanneSThEGreaT
June 22nd, 2009, 02:09 AM
I wasn't answering you, David. :)

gmorris04
June 22nd, 2009, 06:23 AM
Gentlemen, gentlemen. Let's play nice now.

Sorry I didn't mention the operating system. It is either XP or 2000; mostly XP. The company I work for through out the idea of Vista. I found what I needed that will extend VB6's usefulness but I still would like to move to VB.NET. I'll look at MSDN on GetLogicalDrives and see what I can figure out. Like I said before I am new at this VB.NET stuff and anything beyond Basic confuses me; at least until I can find a good book to get me beyond the VB basics. Any ideas on a good book?

HanneSThEGreaT
June 22nd, 2009, 07:41 AM
I don't think anyone's fighting :)

This is a good book to start up with :
http://discuss.fogcreek.com/redirect.asp?http://www.microsoft.com/mspress/books/5199.asp

Good Luck!

dglienna
June 23rd, 2009, 01:25 AM
Plus, here (http://www.microsoft.com/learning/en/us/default.aspx)

gmorris04
June 23rd, 2009, 06:40 AM
Attached is a jpg of what I am looking for. If this is not possible in VB.NET I would like to know so I can turn my attention to other things.

HanneSThEGreaT
June 23rd, 2009, 09:14 AM
Yes, that is absolutely possible - so this is actually what you want. Then, have you looked into the advice David gave in Post #4, and mine in Post #5 ¿

gmorris04
June 23rd, 2009, 10:43 AM
Thanks Hannes. Yes I looked at your suggestion and that gave me the drive letter. That I already know how to do. The ongoing issue is that either no one knows or no one is telling me how to retrieve the device\harddisk info that is associated with the drive letter, like the example shows, in VB.NET. With Davids suggestion I looked at the MSDN and not sure how to implement the GetLogicalDrives() to get what I want. A simple example of inputting the drive letter and getting a msgbox with the device\HardDisk number would help. The type of drive is not important since I don't use it. I tried to port over the VB6 code that I have but with no luck. I found an app in C something that does what I want but looking at the code my eyes glazed over. I started thinking if I take what I have in VB6 and compile it into a separate file and then call it from my .NET program passing it the drive letter and having it return the Harddisk number, but I am not sure how to do that; if it is possible. I don't mind having 2 separate files as long as I can get the info that my .NET app needs.

HanneSThEGreaT
June 23rd, 2009, 11:11 AM
Hello again!

Initially I thought you were actually looking for something more complicated :D

I introduce to you WMI (http://en.wikipedia.org/wiki/Windows_Management_Instrumentation)

I'm attaching two projects with, one in VB6, and one in VB.NET. Neither of which I created, just sourced :)

The VB 6 one is very complete, but, the VB.NET one also shows that VB.NET can do the same, unfortunately not as complete, but I have very limited time currently.

Have a look at these links as well :

http://www.dreamincode.net/code/snippet2514.htm

http://vbnet.mvps.org/index.html?code/disk/index.html

http://vbnet.mvps.org/index.html?code/disk/deviodriveinfo.htm

Have a look at both projects, and see if they help you, I sincerely hope so! :)

Hannes

gmorris04
June 23rd, 2009, 11:40 AM
I found this on the MSDN. What I am looking for is what is called the NT Device Names. maybe you can understand what MS is saying.

http://msdn.microsoft.com/en-us/library/ms794698.aspx

gmorris04
June 23rd, 2009, 11:43 AM
And a bit more on the NT Device Names.

http://msdn.microsoft.com/en-us/library/ms794707.aspx

HanneSThEGreaT
June 23rd, 2009, 11:55 AM
I don't think your completely on the right track, let me have a look closer... :)

Did you have a look at my previous samples, I'm sure they'll be helpful :)

gmorris04
June 23rd, 2009, 12:46 PM
I tried your examples and they were close but the NT Device Name is what I am after. If you go to the link below vbAccelerator is doing exactly what I need but it is in VB6 and not .NET. I tried porting it over to .Net and cleared all but one error, which didn't matter. When I ran it it never even got close to the code with the error that I couldn't fully resolve.

Anyway these guys are retrieving the NT Device Name. The example that I posted earlier was from their program.

http://www.vbaccelerator.com/home/VB/Tips/Mapping_NT_Device_Names/Device_Names_Sample_zip_mDrives_bas.asp

Let me know what you think.

dglienna
June 23rd, 2009, 10:07 PM
I think the answer lies closer to VB.Net using API's

http://www.freevbcode.com/ShowCode.Asp?ID=2707

gmorris04
June 24th, 2009, 07:06 AM
That seems to give me the path to the windows system directory. Not what I need.

Here's my scenario:

I have an USB GPS device, whether it is Garmin, TomTom, Magellan, etc. I have to load the files, also known as an image, for the map and OS into the internal flash memory. The old way of doing this is I simply call the image program and pass the drive letter and the path to the image file. With some of the newer flash memory it requires the physical drive number (i.e. Device\HardDisk1, Device\HardDisk2, Device\HardDisk3, etc.). From looking at the VB6 code I discovered this to be the NT Device Name. So I need to use the drive letter to get the NT Device Name so I can pass this to the image program.

dglienna
June 24th, 2009, 11:51 PM
I don't think they've changed the kernal, but that IS code to give a letter. You had that as well.

The difference is that I showed you how to access the same function, but from VB.Net.

I didn't translate your NT command, but it shouldn't be that hard

HanneSThEGreaT
June 25th, 2009, 02:07 AM
Yeah, either my code or David's code should actually be sufficient, as I understand your situation :) or is there perhaps something else ¿

gmorris04
July 16th, 2009, 01:58 PM
Sorry guys. I have been redirected for the last month and may be the case for another month. To reply to the last post about either one of you guys solutions will be sufficient. Unless I can input the drive letter and have the code spit out the "device\harddisk" number then neither will work. It is imperative that I can get the physical drive number (i.e. Device\HardDisk#) from inputting the drive letter. I don't need it to count how many devices are connected. I need what Microsoft calls NT Device Name.

I will be popping in and out of the forum so as always any help will be greatly appreciated.