VB如何快速运行外部程序
发现用SHELL或者SHELLEXECUTE都好,运行一个外部程序起码需要三秒才能打开,但直接运行一秒左右就行了.为什么会差那么多,有什么方法能够快一些运行呢?
[解决办法]
Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
Private Const SW_RESTORE = 9
Private Sub cmdCommand1_Click()
Dim RET As Integer
RET = WinExec("CALC.EXE", SW_RESTORE)
'Shell "CALC.EXE,1" '利用SHELL将弹出“文件未找到”的错误信息
If RET > 32 Then Print "调用正确" Else Print "调用错误"
End Sub
Private Sub cmdCommand2_Click()
End
End Sub
试试这个可以吗
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
Private Sub Command1_Click()
Dim RET As Integer
RET = ShellExecute(Me.hwnd, "open", "winword.EXE", "", 1, 5)
'Shell "winword.EXE,1" '利用SHELL将弹出“文件未找到”的错误信息
If RET = 0 Then Print "调用错误" Else Print "调用正确"
End Sub
Private Sub Command2_Click()
End
End Sub
[解决办法]
因为系统有缓存。
比如说你第一次打开Word需要5秒,关闭再打开只要1秒。
和是不是ShellExecute调用的无关,不信,你重新启动再打开看看。
[解决办法]