Monitoring an external application

I'd like to write application which would launch some external program and notify me when the program will be closed. I also need possibility to force closing this program. Could anyone help me, please?
LVL 11
ZhaawZSoftware DeveloperAsked:
Who is Participating?
 
mokuleConnect With a Mentor Commented:
To launch program

procedure TForm1.Button1Click(Sender: TObject);
var
  cmd: string;
  procinf: TProcessInformation;
  stinfo: TStartUpInfo;
  exitcode: dword;
begin
    GetStartupInfo(stinfo);
    stinfo.wShowWindow := SW_HIDE;  //SW_SHOW
    cmd := 'some.exe';
    if CreateProcess(nil,PChar(cmd),nil,nil, False,0,  nil,nil,stinfo,procinf) then
      begin
      repeat
        Apprunning := WaitForSingleObject(procinf.hProcess,100) ;
        Application.ProcessMessages;
      until (Apprunning <> WAIT_TIMEOUT) ;
    end;
end;
0
 
mokuleCommented:
To terminate process

TerminateProcess(procinf.hProcess,0);
0
 
mokuleCommented:
One important information. To have possibility to terminate process You must have PROCESS_TERMINATE access right set in Security structure
0
 
ZhaawZSoftware DeveloperAuthor Commented:
tx for the answers ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.