|
-
May 15th, 2000, 10:22 AM
#1
Thread Starter
Member
Could someone please tell me how I can get a vb program on a CD-ROM to call files on the CD-ROM without installing the program to the C Drive. When I try to open a file on the CD-ROM it may not be successful as not everyone has their CD-ROM drive labelled as D Drive. How can it recognise the CD-ROM drive letter and then refer to files on it?
-
May 15th, 2000, 12:49 PM
#2
Lively Member
Here is example code, what show drive letters.
- Dj4
Option Explicit
Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal ndrive As String) As Long
Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Const DRIVE_UNIDENTIFIED = 0
Const DRIVE_NONE = 1
Const DRIVE_REMOVABLE = 2
Const DRIVE_FIXED = 3
Const DRIVE_REMOTE = 4
Const DRIVE_CDROM = 5
Const DRIVE_RAMDISK = 6
Public Sub GetDrivers()
Dim Length As Long
Dim DriverLetter As Long
Dim Buffer As String
Dim Driver As String
Dim Type As String
Dim Position As Integer
Buffer = Space$(2048)
Length = 2047
DriverLetter = GetLogicalDriveStrings(Length, Buffer)
Position = InStr(Buffer, Chr$(0))
While Position > 1
Driver = Left$(Buffer, Position - 1)
Select Case GetDriveType(Driver)
Case DRIVE_UNIDENTIFIED
Type = "Not Identified"
Case DRIVE_NONE
Type = "Not Installed"
Case DRIVE_REMOVABLE
Type = "Removable (Floppy) Drive"
Case DRIVE_FIXED
Type = "Fixed Drive"
Case DRIVE_REMOTE
Type = "Remote (Network) Drive"
Case DRIVE_CDROM
Type = "CD-ROM"
Case DRIVE_RAMDISK
Type = "Ramdisk"
End Select
Buffer = Mid$(Buffer, Position + 1)
Position = InStr(Buffer, Chr$(0))
If Type = "CD-ROM" Then
MsgBox "CD-ROM!!!!"
End If
Wend
End Sub
-
May 15th, 2000, 07:05 PM
#3
New Member
Try this for size
try this for size, will search system settings for cd rom drive's and return back to you the one the drive letter that contains your file, empty means nothing found.
Any comments e-mail me : [email protected]
DECLARES:
Private Declare Function GetDriveType Lib "kernel32" _ Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings _ Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal _ nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Private Const MyMovieName = "capture.mpv"
FUNCTION:
Function GetCDROMDrive() As String
Dim R&, AllDrives$, JustOneDrive$, Pos%, DriveType&
Dim CDfound As Integer, MyCD$, MyLen%, DummyCD$, i%
'pad the string with spaces
AllDrives$ = Space$(64)
'call the API to get the string containing all drives
R& = GetLogicalDriveStrings(Len(AllDrives$), AllDrives$)
If R& = 0 Then
GetCDROMDrive = ""
Exit Function
End If
'trim off trailing chr$(0)'s. AllDrives$ now
'contains all the drive letters.
AllDrives$ = Left$(AllDrives$, R&)
Do
'find the first separating chr$(0)
Pos% = InStr(AllDrives$, Chr$(0))
'if there's one, then...
If Pos% Then
'extract the drive up to the chr$(0)
JustOneDrive$ = Left$(AllDrives$, Pos%)
'and remove that from the Alldrives string,
'so it won't be checked again
AllDrives$ = Mid$(AllDrives$, Pos% + 1, Len _
(AllDrives$))
'with the one drive, call the API to
'determine the drive type
DriveType& = GetDriveType(JustOneDrive$)
'check if it's what we want
If DriveType& = DRIVE_CDROM Then
'get rid of any binary nulls
MyLen% = Len(JustOneDrive$)
For i% = 1 To MyLen%
If Mid(JustOneDrive$, i%, 1) <> _
Chr$(0) Then
DummyCD$ = DummyCD$ & _
Mid(JustOneDrive$, i%, 1)
End If
Next i%
'now test if we have the video on the
'cdrom weare looking at
DummyCD$ = DummyCD$ & MyMovieName
On Error Resume Next
MyCD$ = Dir(DummyCD$)
If MyCD$ <> "" Then
CDfound% = True
Exit Do 'we're done, so get out
End If
End If
End If
Loop Until AllDrives$ = ""
'display the appropriate message
If CDfound% = True Then
GetCDROMDrive = DummyCD$
Else
GetCDROMDrive = ""
End If
End Function
-
May 16th, 2000, 12:12 AM
#4
Thread Starter
Member
OK, thanks guys for the info.
Actually, the problem is that I don't wanna find the drive letter for myself or the user. I need to tell my VB program that search for the CDROM drive letter and then run other apps or utilities using this drive letter from "root" or other subdirectories on the CD. In other word, how can I implement this into the VB code? How can I give the "path"?
I don't have any hair left! :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|