Here is another one that may come in handy for a lot of us. If you want to secure your Visual Basic stand alone application that is distributed in CD you can make the program check each time it runs, if a certain file in the CD was in the CD drive. And if the file in the CD is not in the CD drive then the VB program will give an error message. This is to make certain every user of the application buys the CD to run your VB application.
Check Which Drive Is The CD Drive
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :
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
Public Const DRIVE_FIXED = 3
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_CDROM = 5
Public Const DRIVE_RAMDISK = 6
'Insert the following code to your form:
Private Sub Form_Load()
Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&
Dim CDfound As Integer
allDrives$ = Space$(64)
r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
allDrives$ = Left$(allDrives$, r&)
Do
pos% = InStr(allDrives$, Chr$(0))
If pos% Then
JustOneDrive$ = Left$(allDrives$, pos%)
allDrives$ = Mid$(allDrives$, pos% + 1, Len(allDrives$))
DriveType& = GetDriveType(JustOneDrive$)
If DriveType& = DRIVE_CDROM Then
CDfound% = True
Exit Do
End If
End If
Loop Until allDrives$ = "" Or DriveType& = DRIVE_CDROM
If CDfound% Then
MsgBox "The CD-ROM drive on your system is drive " & UCase$(JustOneDrive$)
Else: MsgBox "No CD-ROM drives were detected on your system."
End If
End Sub
Now write additional functions to check for a file in the CD rom path.