• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

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?
0
ZhaawZ
Asked:
ZhaawZ
  • 3
1 Solution
 
mokuleCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now