Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
In VB Check Which Drive Is The CD Drive

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
dude
Power User
Power User


Joined: 10 Mar 2004
Posts: 376
Location: Savar, Dhaka

Post Post subject: In VB Check Which Drive Is The CD Drive Reply with quote

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.
Wed Jun 23, 04 9:31 am
Back to top
dude View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group