The disc / U disk is required when the program is packaged. It is not known that the drive letter of the disc on the machine is, or if you don't know the category of the drive, the total number of drive characters.
......... You can use the following method to judge .........
The API description to be used:
Returns all the drives on the machine
GetLogicalDriveStrings
VB statement Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Description obtaining a string, which contains the root of the drive path currently all logical drives return value Long, loaded into lpBuffer The number of characters (excluding air stop characters). If the length of the buffer is insufficient, the path cannot be accommodated, the return value becomes the required buffer size. Zero means failure. The GetLasTerror parameter table parameter type will be set and the length lpbufferstring of NBufferLengthlong, the LPBuffer string is used to load the logical drive name. Each name is separated by a NULL character, with two NULL back (empty) after the last name
Different disk types can be judged by getDriveType.
GetDriveType
VB Declaration Declare Function GetDriveType LIB "Keernel32" Alias "getDriveTypea" AS long Description When it is determined that the type return value of a disk drive, if the drive cannot be identified, zero is returned. If the specified directory does not exist, then returns 1. If the execution is successful, use any of the following constants: drive_removable, drive_fixed, drive_remote, drive_cdrom or drive_ramdisk parameter table parameter type and indication NDRIVESTRING, including a string of the drive root directory path
Example as the file specified in the CD: Private Declare Function GetLogicalDrivestrings LIB "kernel32" Alias "getLogicalDrivestrings" (Byval NbufferLength As Long, Byval Lpbuffer AS String) AS Long
Private Declare Function GetDriveType Lib "kernel32" Alias "getDriveTypea" (Byval NDRIVE AS STRING) AS Long
Private sub flow_click ()
DIM STRDRIVE AS STRING 'drive string (A: / C: / D: / ...)
DIM DriveID as string 'drive letter (such as: a: /)
STRDRIVE = String (100, chr $ (0)) 'Initializer string
Call getLogicalDriveStrings (100, strDrive) 'Returns a string
DIM I as integer
'Return to CD to an array
For i = 1 to 100 step 4 'Note this is 4
DriveID = MID (StrDrive, I, 3) 'enumeration plate
If DriveID = CHR $ (0) & chr (0) & chr (0) THEN EXIT for 'No disk, instant exit cycle if getDriveType (driveID) = 5 Ten Call ShellPro
'If the enumerated disk is a CD-ROM, go to the shellpro subroutine
Next I
End Sub
'Subroutine ::::: Open file
Sub shellpro (DrivePro As String)
ON Error Goto Err_File:
IF not isemptycdrom (drouspro) THEN
Shell (DrivePro & "Hello.exe") 'Opens File Path
Unload me
End 'and end this procedure
Else
Debug.print "CD-ROM IS EMPTY"
END IF
Err_File:
If Err.Description = "File Name or Number" "THEN EXIT SUB
End Sub
Function isemptycdrom (SDRIVE AS STRING)
DIM S
ON Error Goto Errhandle
s = DIR (SDRIVE "*. *")
ISemptycdrom = false
EXIT FUNCTION
Errhandle:
ISemptycdrom = true
End function Note: The above code can be called freely, modify ... :)