FAQ一覧へ インデックスへ

他のプログラムの起動、終了待ち(2.0)


質問

WinExecは16BIT様なので、32BITでの他のプログラムの起動方法が知りたい。

又、Delphi2.0では32BIT環境なので、WinExecとGetModuleUsageでは終了待
ちが出来ません。



答え

CreateProcessと、WaitForSingleObjectを使います。

例を参照してください。


Var
   SI :TStartupInfo;
   PI :TProcessInformation;
Begin
  GetStartupInfo(SI);
  If Not CreateProcess('C:\Windows\Notepad.Exe', nil, nil, nil,
                       False,  CREATE_DEFAULT_ERROR_MODE,nil, nil, SI, PI) Then
     Raise Exception.Create('Exec Error ' + IntToStr(GetLastError));
  While WaitForSingleObject(PI.hProcess, 0) = WAIT_TIMEOUT Do
    Application.ProcessMessages;
{このループが抜けたら、起動したプログラムが終了している}
End;