最直接和简单的方法就是使用Shell 函数
本示例使用 Shell 函数来完成一个用户指定的应用程序。
' 将第二个参数值设成 1,可让该程序以正常大小的窗口完成,并且拥有焦点。
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' 完成Calculator。
关于光盘:用下面的的函数将检查你计算机所有的驱动器是否是 CD-ROM,如果是就返回驱动器号,如果没有就返回空字符:
Public Function BI_GetCDROMDrive() As String
Dim lType As Long
Dim i As Integer
Dim tmpDrive As String
Dim found As Boolean
On Error GoTo ErrorHandler
'Loop thru A-Z. If found, exit early.
For i = 0 To 25
tmpDrive = Chr(65 + i) & ":"
lType = GetDriveType(tmpDrive) 'Win32 API 函数
If (lType = DRIVE_CDROM) Then 'Win32 API 常数
found = True
Exit For
End If
Next
If Not found Then
tmpDrive = ""
End If
BI_GetCDROMDrive = tmpDrive
ErrorHandler:
Err.Description = "BI_GetCDROMDrive 失败:不可预料的错误。"
BI_Errorhandler
End Function
调用API函数 ShellExecute
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
shell