Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to close another application (2) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Oct-02
Category
Win API
Language
Delphi 2.x
Views
122
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

I'm using the command CreateProcess(nil, PChar('PKUNZIP 
..."),nil,nil,false,0,nil,nil,SI,PI) to execute PKUNZIP inside my program. But 
after the execution of PKUNZIP the window remains opened. How do I detect if 
PKUNZIP finishes its execution and how do I close the window after that?

Answer:

Closing it gently :

1   { ... }
2   var
3     Handle: THandle;
4   begin
5     Handle := FindWindow(classname, windowname); {Look this one up in the help file 
6   ...}
7     if Handle <> 0 then
8       if MessageBox(Handle,
9         PChar('Do you really want me to try to kill this application ?'),
10        'Please Confirm', MB_YESNO) = mrYES then
11      begin
12        PostMessage(Handle, WM_QUIT, 0, 0);
13      end;
14  end;
15  
16  //To close it with more brute force:
17  
18  procedure TggProcessViewer.KillProcess(hProcess: THandle);
19  var
20    PH: THandle;
21    lpExitCode: DWord;
22  begin
23    PH := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION, false, 
24  hProcess);
25    if PH <> 0 then
26    begin
27      if GetExitCodeProcess(PH, lpExitCode) then
28      begin
29        if MessageBox(Handle,
30          PChar('Do you really want me to try to kill this process ?'),
31          'Please Confirm', MB_YESNO) = mrYES then
32        begin
33          TerminateProcess(PH, lpExitCode);
34          MessageBox(Handle, PChar('should be dead now...'), PChar('Check it out...'),
35            MB_OK);
36        end;
37      end
38      else
39        MessageBox(Handle, PChar('Could not retreive the ExitCode for this process.' +
40          #13 + #13 + SysErrorMessage(GetLastError)),
41          PChar('Something went wrong...'), MB_OK);
42      CloseHandle(PH);
43    end
44    else
45      MessageBox(Handle, PChar('Could not get access to this process.' + #13 + #13
46        + SysErrorMessage(GetLastError)), PChar('Something went wrong...'),
47        MB_OK);
48    Refresh;
49  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC