Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Const Process_Query_Information = &H400 Public Const Still_Active = 259 Sub 按钮186_单击() Dim strWinDir As String Dim pid As Long Dim hProcess As Long Dim a As String a = ThisWorkbook.Path 'Excell文件所在路径。 strWinDir = Environ("windir") '系统目录。 'pid = Shell(strWinDir & "\system32\cmd.exe", 1) pid = Shell(a & "\cuihuatiaohe.exe", 1) hProcess = OpenProcess(Process_Query_Information, False, pid) Do GetExitCodeProcess hProcess, lngexitcode DoEvents Loop While lngexitcode = Still_Active End Sub
以上语句,我执行pid = Shell(strWinDir & "\system32\cmd.exe", 1) 时该cmd窗口可以长时间存在,而我执行pid = Shell(a & "\cuihuatiaohe.exe", 1) 则cuihuatiaohe.exe运行很短的时间马上就自动终止,并没有执行完。我不用VBA调用,直接运行该程序cuihuatiaohe.exe没有任何问题,可以正常运行(大约10秒)。 这是为什么呢?感觉好像是cuihuatiaohe.exe被调用后显示出一行字后就自动中断了。
|