Solved

Executing aplications from delphi programas

Posted on 1998-04-17
6
249 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
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 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 40 total points
ID: 1334827
See comment below.

Scott
0

Featured Post

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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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