Solved

Monitoring an external application

Posted on 2004-04-13
4
540 Views
Last Modified: 2010-04-05
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
Comment
Question by:ZhaawZ
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 10817777
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
 
LVL 17

Expert Comment

by:mokule
ID: 10817811
To terminate process

TerminateProcess(procinf.hProcess,0);
0
 
LVL 17

Expert Comment

by:mokule
ID: 10817979
One important information. To have possibility to terminate process You must have PROCESS_TERMINATE access right set in Security structure
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 10821048
tx for the answers ;)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 242
Why can't I create any project with my delphi EXE file? 6 39
Wincontrol not (correctly) drawn 15 42
shape, triangle, dbctrlgrid 3 17
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question