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 execute a console application from a Delphi program 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
System
Language
Delphi 2.x
Views
92
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

This executes a console application, but if your application is not a console, just 
remove CREATE_NEW_CONSOLE.
1   
2   function RunApp(const aCmd: string; aWait: boolean; aShowMode: integer): DWORD;
3   var
4     StartUpInfo: TStartUpInfo;
5     ProcessInfo: TProcessInformation;
6     WaitCode: DWORD;
7   begin
8     Result := 0;
9     ZeroMemory(@StartupInfo, SizeOf(TStartupInfo));
10    StartUpInfo.cb := SizeOf(StartUpInfo);
11    StartUpInfo.wShowWindow := aShowMode;
12    StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
13    ZeroMemory(@ProcessInfo, SizeOf(TProcessInformation));
14    Win32Check((CreateProcess(nil, PChar(aCmd), nil, nil, False, CREATE_NEW_CONSOLE +
15      NORMAL_PRIORITY_CLASS, nil, nil, StartUpInfo, ProcessInfo)));
16    try
17      if aWait then
18      begin
19        repeat
20          WaitCode := WaitForSingleObject(ProcessInfo.hProcess, 10000);
21          Win32Check(WaitCode < > WAIT_FAILED);
22          if WaitCode = WAIT_TIMEOUT then
23          begin
24            if MessageDlg('This is a test', mtWarning, [mbYes, mbNo], 0) < > mrYes 
25  then
26              Break;
27          end
28          else
29            Break;
30        until
31          False;
32        Win32Check(GetExitCodeProcess(ProcessInfo.hProcess, Result));
33      end;
34    finally
35      CloseHandle(ProcessInfo.hThread);
36      CloseHandle(ProcessInfo.hProcess);
37    end;
38  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