Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

See if an application is running

Posted on 1999-07-03
25
Medium Priority
?
145 Views
Last Modified: 2010-04-06
How can I see if an application which I have started from my program such as ftp.exe has been finished the execution?
0
Comment
Question by:iliescufm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 4
  • +2
25 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1385991
You can use CreateProcess and store the resulting process parameter.

p := CreateProcess(....)

then you do:

while WaitForSingleObject(p, 100) = WAIT_TIMEOUT do ;

Good luck..

If you need to know how to fil the params of CreateProcess respond

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1385992
Sorry forgot to check E-mail notify
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385993
Jacco is right. Here comes a full source example:

unit runThread_;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
  ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var Form1 : TForm1 = nil;

implementation

{$R *.DFM}

const unitName = 'runThread_.';

type TRunThread = class(TThread)
  private
    processHandle : cardinal;
    processReady  : boolean;
    waitingThread : cardinal;
    procedure Execute; override;
  end;

procedure TRunThread.Execute;
begin
  WaitForSingleObject(processHandle,INFINITE);   // This call does not return, unless copy is stopped
  processReady:=true;                            // Set "processReady" flag for main thread
  PostThreadMessage(waitingThread,WM_NULL,0,0);  // Wake up main thread
                                                 // If you call Application.HandleMessage (see below) in the
                                                 // main thread, the main thread is sleeping the most time in
                                                 // winAPI "waitMessage". So we send a "dummy" message in order
                                                 // to let the main thread return from Application.HandleMessage
end;

procedure TForm1.Button1Click(Sender: TObject);
var si  : TStartupInfo;
    pi  : TProcessInformation;
    dw1 : dword;
begin
  enabled:=false;
  caption:='start copy...';
  ZeroMemory(@si,sizeOf(si)); si.cb:=sizeOf(si);
  si.dwFlags:=STARTF_USESHOWWINDOW; si.wShowWindow:=SW_HIDE;
  if CreateProcess(nil,'c:\command.com /c copy c:\autoexec.bat c:\test.bat >c:\output.txt',nil,nil,false,0,nil,nil,si,pi) then begin
    caption:='copy started...';
    with TRunThread.Create(true) do         // create the thread object, but do not start it now...
      try
        processHandle:=pi.hProcess;         // tell the thread what process it has to watch
        processReady:=false;                // flag for the loop (see below)
        waitingThread:=GetCurrentThreadID;  // the current threadID for the wakeup message (see above)
        caption:='wait for copy...';
        Resume;                             // now all information is prepared; so let's start the thread
        repeat
          Application.HandleMessage;        // message loop
        until Application.Terminated or processReady;  // continue with normal program when either the
                                                       // started process has stopped or our program is closed
        caption:='copy stopped...';
      finally Free end;
    GetExitCodeProcess(pi.hProcess,dw1);
    CloseHandle(pi.hThread); CloseHandle(pi.hProcess); // Never forget to close handles...
    caption:='ready... (exitCode='+IntToStr(dw1)+')';
  end else caption:='could not start copy...';
  enabled:=true;
end;

end.

BTW, Jacco, you don't need to write a new comment to enable EMail notification. Just leave the edit field empty, don't check comment/answer, check the notify box and hit Submit. That works without adding a new (empty) comment. I've already tested that...   :-)
0
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!

 
LVL 10

Expert Comment

by:Jacco
ID: 1385994
Thanx Mashdi!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385995
Madshi! Not Mashdi...   :-)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385996
It's really easy, just remember, I'm mad... "mad-shi"...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1385997
shi is really mad, hehe.... :))

btw, Madshi, it does not work with just checking the box and submitting with the edit box being empty.... that's not gonna work, because as soon as the answer is accepted you won't be able to view the question, unless you've added a REAL comment to it... Do you understand what I'm trying to say?? I've tested it... that way, if you're learning from other questions that people answer, you'll not get the final solution to a problem especially if you';re away form the computer and then you can't go back and view the whole question etc...

-vik-
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385998
Hi Vik,

though, I'm a he, not a shi...   :-)

not in this case. Jacco already had written a comment to this question. So in this case it would have worked perfectly with only checking the box.
But generally you're right. Without writing a "real" comment to a question, you can't read the comments/answer, once the answer is accepted, without paying for it.

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1385999
>>though, I'm a he, not a shi...   :-)
are you sure about that??



hehe, just kiddin' ;-)))

how is it goin around here?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386000
Well, it's goin ok. Not many shis here for a he like me...   :-(
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1386001
hehe... :))
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1386002
Question answered?

Regards Jacco

I'll remember Madshi
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1386003
well Madshi, I can transfer you in a 'she' if you want. I've got a spell somewhere...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386004
AAAAAAAAAH - don't - *PLEASE*!!!

There's a fantastic girl in my church waiting to be dated someday (when she's old enough). It would be a quite bad spell for me...   :-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1386005
hoho, how old is she now? 5? hehe ;))
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386006
No - 17, but not grownup enough...   :-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1386007
you call me not grown up enough?? I mean 'cuz I'm 17 too ;D
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386008
Hehe...  :-)
I didn't mean that all 17 year old humans are not grownup enough. I meant THIS one specific girl is with her 17 years not grownup enough for me...  (-:
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1386009
hehe okay ;D
0
 

Author Comment

by:iliescufm
ID: 1386010
Thanks to Jacco, and al lot of thanks to Madshi.
0
 

Author Comment

by:iliescufm
ID: 1386011
Thanks to Jacco, and a lot of thanks to Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386012
Hi lilescufm, to whom do you want to give the points?   :-)
0
 

Author Comment

by:iliescufm
ID: 1386013
I want to give the points to Madshi, how can I do that?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 1386014
I must first answer the question. Now you can accept my answer. Thanx for the points...   :-)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1386015
P.S: Sorry to Jacco...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

722 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