Registriert seit: 29. Jan 2004
Ort: Heusenstamm
420 Beiträge
Delphi 2005 Professional
|
Re: D5P: ShellExecute soll warten
28. Jan 2005, 16:33
moin,
versuchs mit folgender Funktion:
(Die habe ich übrigens auch irgendwo hier gefunden. Das nächstemal bitte die Suche bemühen!)
Delphi-Quellcode:
uses
ShellAPI, {Shellexecute}
Windows, {WaítforSingleObject}
Forms, {Application.}
SysUtils; {TSearchRec, Findfirst, etc.}
{ Messages, Variants, Classes, Graphics, Controls,
Dialogs; }
function ShellExecuteAndWait(Operation, FileName, Parameter, Directory: string;
Show: Word; bWait: Boolean): Longint;
implementation
function ShellExecuteAndWait(Operation, FileName, Parameter, Directory: string;
Show: Word; bWait: Boolean): Longint;
var
bOK: Boolean;
Info: TShellExecuteInfo;
{
****** Parameters ******
Operation:
edit Launches an editor and opens the document for editing.
explore Explores the folder specified by lpFile.
find Initiates a search starting from the specified directory.
open Opens the file, folder specified by the lpFile parameter.
print Prints the document file specified by lpFile.
properties Displays the file or folder's properties.
FileName:
Specifies the name of the file or object on which
ShellExecuteEx will perform the action specified by the lpVerb parameter.
Parameter:
String that contains the application parameters.
The parameters must be separated by spaces.
Directory:
specifies the name of the working directory.
If this member is not specified, the current directory is used as the working directory.
Show:
Flags that specify how an application is to be shown when it is opened.
It can be one of the SW_ values
bWait:
If true, the function waits for the process to terminate
}
begin
FillChar(Info, SizeOf(Info), Chr(0));
Info.cbSize := SizeOf(Info);
Info.fMask := SEE_MASK_NOCLOSEPROCESS;
Info.lpVerb := PChar(Operation);
Info.lpFile := PChar(FileName);
Info.lpParameters := PChar(Parameter);
Info.lpDirectory := PChar(Directory);
Info.nShow := Show;
bOK := Boolean(ShellExecuteEx(@Info));
if bOK then
begin
if bWait then
begin
while WaitForSingleObject(Info.hProcess, 100) = WAIT_TIMEOUT
do Application.ProcessMessages;
bOK := GetExitCodeProcess(Info.hProcess, DWORD(Result));
end
else
Result := 0;
end;
if not bOK then Result := -1;
end;
Peter Enenkel blubb
|
|
Zitat
|