# Re: 以Shell呼叫其他程式??

Posted by lee on March 20, 1999 at 17:16:44:

In Reply to: 以Shell呼叫其他程式?? posted by Lai on March 19, 1999 at 13:25:12:

: 我以Shell函数呼叫其他程式(.exe)执行时
: 为何被呼叫的程式尚未执行完成就结束
: 回到原来呼叫的下一行句子,何故?可有解决之道?
: 请协助.thanks..

API 的宣告：

Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

程式范例：(以执行 Notepad 程式为例)

Dim pId As Long, pHnd As Long
pId = Shell("Notepad", vbNormalFocus)

pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Call WaitForSingleObject(pHnd, INFINITE)
Call CloseHandle(pHnd)
End If

Follow Ups: