linuxrox
asked on
determine hard drive number from the actual drive letter
hello, i'm writing an application that i need to determine the drive number like 0, 1, 2 etc etc from the drive letter assigned to it. so if i have a c:\ d:\ e:\ drive assignments, how can i determine for instance, if my program is installed on the e:\drive instead of the c:\ drive, which actual drive number assignment has windows given it? is this possible?
thanks!
thanks!
App.Path will give you the drive and path to where your program is installed
ASKER
yes i know that : )
but i need the actual drive number like 0, 1, 2 etc etc.
trying to get the drive number if you DO know the letter.
but i need the actual drive number like 0, 1, 2 etc etc.
trying to get the drive number if you DO know the letter.
Linux Rocks? In a VB forum? That's rich...
Since C:\ is (always? 99.99%?) the main (or, root) directory, if you assign C=0, then D=1, E=2, etc.
Since C:\ is (always? 99.99%?) the main (or, root) directory, if you assign C=0, then D=1, E=2, etc.
ASKER
LOL
Badotz: i have to cover a lot of ground!!! : )
Linux handles all my server related stuff, PHP/mysql-apache, firewalling....
windows = applications! : )
someone said in VB.NET you could use:
In VB.net you can use:
Dim i As Integer = 1
Dim ImOnDrive As String = "C:\"
For Each x As System.IO.DriveInfo In My.Computer.FileSystem.Dri ves
If ImOnDrive = x.ToString Then MsgBox("I'm on drive: " & i) : Exit For Else i += 1
Next x
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
not sure what that equates to in VB6 though or if it's possible.
Badotz: i have to cover a lot of ground!!! : )
Linux handles all my server related stuff, PHP/mysql-apache, firewalling....
windows = applications! : )
someone said in VB.NET you could use:
In VB.net you can use:
Dim i As Integer = 1
Dim ImOnDrive As String = "C:\"
For Each x As System.IO.DriveInfo In My.Computer.FileSystem.Dri
If ImOnDrive = x.ToString Then MsgBox("I'm on drive: " & i) : Exit For Else i += 1
Next x
--------------------------
not sure what that equates to in VB6 though or if it's possible.
There's a Dir object in VB6 - not sure if it is "auto-populated" or not, but it might be woth a shot.
ASKER
not sure what all the Dir object does but i'm not needing the drive letter..that's simple.
i need the number.....the drive number(location)... 0, 1, 2 etc etc
i understand your logic on your previous post about the 99.99 percent of the time...but there must be a way to actually determine a drives location such as 0, 1, or 2 if you know it's letter such as c, d, or e.
i need the number.....the drive number(location)... 0, 1, 2 etc etc
i understand your logic on your previous post about the 99.99 percent of the time...but there must be a way to actually determine a drives location such as 0, 1, or 2 if you know it's letter such as c, d, or e.
Dim dNum
dNum = Asc$(UCase$(Mid$(DriveLett er,1,1))) - 65
Seems like a lot of work :-/
dNum = Asc$(UCase$(Mid$(DriveLett
Seems like a lot of work :-/
hmmm...put it in a Function?:
Function getDriveNumber(byval Drv as String) As Integer
getDriveNumber= CInt(Asc$(UCase$(Mid$(Driv eLetter,1, 1))) - 65)
End Function
Function getDriveNumber(byval Drv as String) As Integer
getDriveNumber= CInt(Asc$(UCase$(Mid$(Driv
End Function
I don't personally know of a pure VB method, but you can either use WMI or if you're using XP/2k3 - you can use diskpart...
Would you be interested in either of these?
Would you be interested in either of these?
Besides what are you expecting to get back when c: d: e: are all on the same physical drive ?
ASKER
hes: i would expect to get the drive number that c, d, and e are on; doesn't matter to me that they are on the same physical drive.
Do you mean the drive number from a boot.ini perspective? Thats the only place I'm aware of that a drive gets a logical number. How will the drive number be used?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wow. All that for [0,1,2...]
Who knew?
Who knew?
Haha...well the output would read...
C: is located on Disk #0, Partition #0
for every disk found...
C: is located on Disk #0, Partition #0
for every disk found...
ASKER
Sirbounty: that may very well work. because then i could simply do an if/then within that loop to see if c: is indeed the drive letter that my app is installed in. so that code will work fine in VB6 right? do i need to make reference to anything special within the project?
No, I don't believe so...but it is not 'technically' pure vb code.
There may be a pure vb method for querying wmi - I've just gotten so used to doing it via vbscript, that I've not really looked.
But I did test it as-is under vb6 with no references and no problems...
There may be a pure vb method for querying wmi - I've just gotten so used to doing it via vbscript, that I've not really looked.
But I did test it as-is under vb6 with no references and no problems...
ASKER
ok, think that should work under win2k, xp and 2003? possibly vista?
ASKER
i got runtime error 424 object required..
ASKER
this gives that error:
(i have serial ATA drives by the way)
Private Sub Form_Load()
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
Dim objWMI: Set objWMI = GetObject("winmgmts:\\.\ro ot\cimv2")
Set colItems = objWMI.ExecQuery("Select * From Win32_LogicalDiskToPartiti on", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
wscript.echo Mid(objItem.Dependent, InStr(LCase(objItem.Depend ent), "deviceid") + 9) & " is located on " & _
Mid(objItem.Antecedent, InStr(LCase(objItem.Antece dent), "deviceid") + 9)
wscript.echo
Next
Set objWMI = Nothing
End Sub
(i have serial ATA drives by the way)
Private Sub Form_Load()
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
Dim objWMI: Set objWMI = GetObject("winmgmts:\\.\ro
Set colItems = objWMI.ExecQuery("Select * From Win32_LogicalDiskToPartiti
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
wscript.echo Mid(objItem.Dependent, InStr(LCase(objItem.Depend
Mid(objItem.Antecedent, InStr(LCase(objItem.Antece
wscript.echo
Next
Set objWMI = Nothing
End Sub
Probably the wscript.echo lines
Replace them with debug.print, or msgbox or however you're wanting to output it..
Replace them with debug.print, or msgbox or however you're wanting to output it..
ASKER
yea that did it dude....think of any reason that wouldn't run on vista? then again, it just came out.. : )
Can't say for sure..haven't played much with it - but I'd lean more towards probably - than not..
Thanx!
Happy to have helped. :^ )
Happy to have helped. :^ )
ASKER
no problemo...now just gotta find a good datagrid component for VB6!!! suckers aren't cheap it doesn't seem!
thanks for the help!
thanks for the help!