On 02 Jul 96 Tommy Usher said to Ray Zelmer...
RZ>I want to run a DOS bat file from a Delphi program (Backup.bat).
TU> HOWEVER, if you need to get fancy, and have the calling
TU> program wait, there is a shareware component that will do this.
No need for shareware ...
WinExecAndWait was posted here by Viggo Poulsen on Nov. 23 '95.
---------------------------------------------------------------------
function WinExecAndWait(Path : Pchar; Visibility : word) : word;
var
InstanceID : THandle;
Msg : TMSg;
begin
InstanceID := WinExec(Path,Visibility);
if InstanceID < 32 then { a value less than 32 indicates an Exec error }
WinExecAndWait := InstanceID
else
repeat
while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
if Msg.Message = WM_QUIT then
halt(Msg.wParam);
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
until GetModuleUsage(InstanceID) = 0;
end;
---------------------------------------------------------------------
Viggo should win a prize for the "most frequently-reposted code" :-)
You might want to wrap a shell around it that will accept a Pascal string
as the path argument. Or you can use the "@1" trick to fake a pChar ...
var s : string ;
s := 'BACKUP.BAT' ; s := s + #0 ;
dec(s[0]) ; { not needed if don't need to re-use s as a pascal string later }
WinExecAndWait(@s[1],SW_SHOWMAXIMIZED) ;
MessageDlg('Backup complete, remove disk from A:',mtInformation,[mbOK],0) ;
--- PPoint 2.00
---------------
* Origin: Kingston, Canada (1:249/109.11)
|