有些程序使用RunApp()命令启动毫无反应,这种情况下,我们需要使用Win32API来实现启动执行程序的功能,代码例子如下:
- //介绍: 部分应用程序无法使用RunApp命令打开, 故这里提供一个API启动程序命令
- //下面两行是API的声明, 请放在脚本开头
- Private Declare Function GetDesktopWindow Lib "user32" () As Long
- Private 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
- //程序路径: 要启动程序的完整路径
- Sub zmRunApp(程序路径)
- Dim p, DirPath, FileName
- p = InStrRev(程序路径, "\")
- DirPath = Left(程序路径, p)
- FileName = Right(程序路径, Len(程序路径) - p)
- ShellExecute GetDesktopWindow, "open", FileName, vbNullString, DirPath, 5
- End Sub
- //调用例子如下:
- zmRunApp "C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe"