-
Nov 3rd, 1999, 06:35 PM
#1
Thread Starter
New 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. I am at the stage where I can autorun the program, but when I ask the program 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? I have been pulling my hair out on this one!
-
Nov 3rd, 1999, 08:07 PM
#2
New Member
Hi!
I found sample code for recognizing which drive on computer is CD:
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) _
As Long
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_NOROOT = 1
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 Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Function dhGetDrivesByString(colDrives As Collection) _
As Integer
Dim strBuffer As String
Dim lngBytes As Long
Dim intPos As Integer
Dim intPos2 As Integer
Dim strDrive As String
Set colDrives = New Collection
strBuffer = Space(255)
' Get the logical drive string
lngBytes = GetLogicalDriveStrings( _
Len(strBuffer), strBuffer)
intPos2 = 1
intPos = InStr(intPos2, strBuffer, vbNullChar)
Do Until intPos = 0 Or intPos > lngBytes
' Parse out the drive letter
strDrive = Mid(strBuffer, intPos2, intPos - intPos2)
' Add it to the collection
colDrives.Add strDrive, strDrive
' Find the next drive letter
intPos2 = intPos + 1
intPos = InStr(intPos2, strBuffer, Chr(0))
Loop
dhGetDrivesByString = colDrives.Count
End Function
And use of function:
Dim lngType As Long
Dim colDrives As Collection
Dim varDisk As Variant
If dhGetDrivesByString(colDrives) > 0 Then
For Each varDisk In colDrives
lngType = GetDriveType(CStr(varDisk))
If lngType = DRIVE_CDROM Then
' varDisk is label of CD-ROM
End If
Next
End If
[This message has been edited by Maxi (edited 11-04-1999).]
-
Nov 3rd, 1999, 08:39 PM
#3
Addicted Member
Don't forget that VB runtimes must be installed in the PC. Also you cannot use DB's like if you had it in your Hard drive.
This function will return you something like "D:\" if you have a CD or "ERROR" if haven't.
In project:
Private Function CheckCD() As String
Dim r As Long
Dim DriveType As Long
Dim allDrives As String
Dim JustOneDrive As String
Dim CDLabel2 As String
Dim pos As Integer
Dim cont As Integer
Dim CDfound As Boolean
allDrives = Space$(64)
r = GetLogicalDriveStrings(Len(allDrives), allDrives)
allDrives = Left$(allDrives, r)
pos = InStr(allDrives, Chr$(0))
CDfound = False
cont = 1
While cont <= pos And CDfound = False
If pos Then
JustOneDrive = Left$(allDrives, 3)
allDrives = Mid$(allDrives, pos + 1)
DriveType = GetDriveType(JustOneDrive)
If DriveType = DRIVE_CDROM Then
CDfound = True
End If
End If
cont = cont + 1
Wend
If CDfound = True Then
CheckCD = JustOneDrive
Else
CheckCD = "ERROR"
End If
End Function
You have to had a module with:
Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Public Const DRIVE_CDROM = 5
Jorge Ledo
j_ledo@hotmail.com
[This message has been edited by JorgeLedo (edited 11-04-1999).]
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
|