Private Declare Function OpenProcess Lib
Private Declare Function GetExitCodeProcess Lib
Private Declare Function CloseHandle Lib
Const PROCESS_QUERY_INFORMATION = &H
Const STILL_ALIVE = &H
Private Sub Command
Dim pid As Long
pid = Shell(
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
Do
Call GetExitCodeProcess(hProcess
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
MsgBox (
End Sub
摘自原文如下
VB啟動/結束另一程序(Shell 等待程序運行結束)
VB 中
第一個問題
首先要知道的是
的指令能夠生效
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
ExitEvent = WaitForSingleObject(hProcess
Call CloseHandle(hProcess)
上例會無限等待shell指令create之process結束後
Dim pid As Long
pid = Shell(
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
isDone = False
Do
Call GetExitCodeProcess(hProcess
Debug
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
isDone = True
另外
下的方式
Dim pid As Long
Dim hwnd
pid = Shell(
hwnd
isDone = False
Do While IsWindow(hwnd
DoEvents
Loop
isDone = True
而如何強迫shell所Create的process結束呢
If hProcess <>
aa = TerminateProcess(hProcess
End If
hProcess便是先前的例子中所取得的那個Process Handle
Call GetExitCodeProcess(hProcess
Debug
DoEvents
Loop While ExitCode = STILL_ALIVE
Debug
而執行了 TerminateProcess(hProcess
另外
可是卻遇上aa
那是執行
(ByVal dwDesiredAccess As Long
ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib
(ByVal hHandle As Long
Private Declare Function CloseHandle Lib
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib
(ByVal hProcess As Long
Private Declare Function TerminateProcess Lib
(ByVal hProcess As Long
Private Declare Function GetForegroundWindow Lib
Private Declare Function IsWindow Lib
(ByVal hwnd As Long) As Long
Const PROCESS_QUERY_INFORMATION = &H
Const STILL_ALIVE = &H
Const INFIN
Private ExitCode As Long
Private hProcess As Long
Private isDone As Long
Private Sub Command
Dim pid As Long
pid = Shell(
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
isDone = False
Do
Call GetExitCodeProcess(hProcess
Debug
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
isDone = True
End Sub
Private Sub Command
Dim pid As Long
Dim ExitEvent As Long
pid = Shell(
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
ExitEvent = WaitForSingleObject(hProcess
Call CloseHandle(hProcess)
End Sub
Private Sub Command
Dim aa As Long
If hProcess <>
aa = TerminateProcess(hProcess
End If
End Sub
Private Sub Command
Dim pid As Long
Dim hwnd
pid = Shell(
hwnd
isDone = False
Do While IsWindow(hwnd
DoEvents
Loop
isDone = True
End Sub
Private Sub Command
Dim pid As Long
pid = Shell(
End Sub
「Modest」
在使用shell後
請看源程
Public Declare Function OpenProcess Lib
Public Declare Function WaitForSingleObject Lib
Public Declare Function CloseHandle Lib
Dim lngPId As Long
Dim lngPHandle As Long
lngPId = Shell(
lngPHandle = OpenProcess(SYNCHRONIZE
If lngPHandle <>
Call WaitForSingleObject(lngPHandle
Call CloseHandle(lngPHandle)
End If
需要注意的是
?boardid=
【laviewpbt】:
Private Declare Function WaitForSingleObject Lib
Private Declare Function CloseHandle Lib
Private Declare Function ShellExecuteEx Lib
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon_OR_Monitor As Long
hProcess As Long
End Type
Private Sub Form_Load()
Dim si As SHELLEXECUTEINFO
si
si
si
si
si
si
si
ShellExecuteEx si
If si
WaitForSingleObject si
CloseHandle si
MsgBox
End If
End Sub
From:http://tw.wingwit.com/Article/program/net/201311/11359.html