?
Solved

Executing aplications from delphi programas

Posted on 1998-04-17
6
Medium Priority
?
253 Views
Last Modified: 2010-04-06
How can I make a WinExecAndWait in Windows 95/NT ???
or something like this.
0
Comment
Question by:jpussacq
[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
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:millerw
ID: 1334822
Try this.  It comes directly out of the Code Librarian in GExperts for Delphi 3.  

{ShellExecute spawns a process asynchronously.  It's as designed that your app
doesn't "wait on" the ShellExecute call for the called app to terminate.

Here's a 32-bit version of "WinExecAndWait":}

 function WinExecAndWait32(FileName:String; Visibility : integer):integer;
 { returns -1 if the Exec failed, otherwise returns the process' exit
   code when the process terminates }
 var
   zAppName:array[0..512] of char;
   zCurDir:array[0..255] of char;
   WorkDir:String;
   StartupInfo:TStartupInfo;
   ProcessInfo:TProcessInformation;
 begin
   StrPCopy(zAppName,FileName);
   GetDir(0,WorkDir);
   StrPCopy(zCurDir,WorkDir);
   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
   StartupInfo.cb := Sizeof(StartupInfo);
   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   if not CreateProcess(nil,
     zAppName,                      { pointer to command line string }
     nil,                           { pointer to process security attributes }
     nil,                           { pointer to thread security attributes }
     false,                         { handle inheritance flag }
     CREATE_NEW_CONSOLE or          { creation flags }
     NORMAL_PRIORITY_CLASS,
     nil,                           { pointer to new environment block }
     nil,                           { pointer to current directory name }
     StartupInfo,                   { pointer to STARTUPINFO }
     ProcessInfo) then              { pointer to PROCESS_INF }
      Result := -1
   else
      begin
      WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
      GetExitCodeProcess(ProcessInfo.hProcess,Result);
      end;
 end;

{OR}

 function WinExecAndWait32(FileName:String; Visibility : integer):integer;
 { returns -1 if the Exec failed, otherwise returns the process' exit
   code when the process terminates }
 var
   zAppName:array[0..512] of char;
   lpCommandLine:array[0..512] of char;
   zCurDir:array[0..255] of char;
   WorkDir:String;
   StartupInfo:TStartupInfo;
   ProcessInfo:TProcessInformation;
 begin
   StrPCopy(zAppName,'');
   StrPCopy(lpCommandLine,FileName);
   GetDir(0,WorkDir);
   StrPCopy(zCurDir,WorkDir);
   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
   StartupInfo.cb := Sizeof(StartupInfo);

   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   if not CreateProcess(
     nil,                           { pointer to command line string }
     lpCommandLine,
     nil,                           { pointer to process security attributes }
     nil,                           { pointer to thread security attributes}
     false,                         { handle inheritance flag }
     CREATE_NEW_CONSOLE or          { creation flags }
     NORMAL_PRIORITY_CLASS,
     nil,                           { pointer to new environment block}
     nil,                           { pointer to current directory name }
     StartupInfo,                   { pointer to STARTUPINFO }
     ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
   else begin
     WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
     GetExitCodeProcess(ProcessInfo.hProcess,Result);
   end;
end;
-----------------------------------------
Scott
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1334823
For these purposes I use an excellant freeware component :

The TExecFile is a non-visual component which you place onto your form to enable easily initiated execution of other Windows or DOS applications from within your own original Delphi application.  This is the third release of the TExecFile and is designed for use with Delphi 2.0 in 32-bit applications designed to run in Windows 95/NT or Win32s environments.

TExecfile from Kevin Savko.

I can send it to you by mail, or you can find it in Torry's or Super delphi pages...

Regards, Zif.

0
 

Author Comment

by:jpussacq
ID: 1334824
millerw:

Tank you, WinExecAndWait32 solve my problem.-
0
Industry Leaders: 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 1

Expert Comment

by:millerw
ID: 1334825
Want me to post it an an answer?
0
 

Author Comment

by:jpussacq
ID: 1334826
Yes, millerw.-
0
 
LVL 1

Accepted Solution

by:
millerw earned 160 total points
ID: 1334827
See comment below.

Scott
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

752 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