タイトル | : Re^2: batファイルの終了を待つにはどうすればいいのでしょうか・・? |
記事No | : 12627 |
投稿日 | : 2008/06/24(Tue) 13:06 |
投稿者 | : おー |
いなさんのおっしゃるサンプルで昔こんなのを書いたことがありました。(サンプルのように簡潔ではないですが・・)
Public Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Public Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessID As Long) As Long Public Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Public Const PROCESS_QUERY_INFORMATION = &H400 Public Const STILL_ACTIVE = &H103&
Private Sub Command1_Click() '-------------------------------- Dim dwProcessID As Long Dim hProcess As Long Dim lpdwExitCode As Long Dim ret As Long '-------------------------------- Dim strShell As String Dim strBatName As String 'バッチファイル名称
'-- a.bat起動 -- strBatName= App.Path & "\a.bat" strShell = "Cmd.exe /c " & strBatName dwProcessID = Shell(strShell, vbMinimizedNoFocus) hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, True, dwProcessID) Do ret = GetExitCodeProcess(hProcess, lpdwExitCode) DoEvents Loop While (lpdwExitCode = STILL_ACTIVE) ret = CloseHandle(hProcess)
'-- a.bat終了後b.bat起動 -- strBatName= App.Path & "\b.bat" strShell = "Cmd.exe /c " & strBatName dwProcessID = Shell(strShell, vbMinimizedNoFocus) hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, True, dwProcessID) Do ret = GetExitCodeProcess(hProcess, lpdwExitCode) DoEvents Loop While (lpdwExitCode = STILL_ACTIVE) ret = CloseHandle(hProcess) End Sub
|