Tom Knowlton
asked on
CreateProcess okay, but DOS "window" doesn't close
Consider the following code:
procedure TFormMain.DeleteTempFolder ;
var
SI : TStartUpInfo;
PI : TProcessInformation;
JARTempDir : string;
begin
FillChar(SI, sizeof(SI), 0);
SI.cb := sizeof(SI);
JARTempDir := ExtractFilePath(Applicatio n.ExeName) + 'Temp';
CreateProcess(nil, pchar('C:\windows\command\ deltree /Y ' + JARTempDir),
nil, nil, False, 0, nil, nil, SI, PI);
end;
CreateProcess opens a DOS window and performs the deltree operation just fine. BUT, the window stays open.
How do I get the window to close when the deltree operation is complete?
Ideally, the DOS window would not be displayed at all.
Can someone who is well-versed on the CreateProcess function help me out here?
Is there an alternative to CreateProcess I can use to perform the deltree command? Perhaps some obscure Delphi file i/o command that can delete entire directories?
I know I've asked several questions here, but they all revolve around a common theme:
Performing "silent" command-line routines.
procedure TFormMain.DeleteTempFolder
var
SI : TStartUpInfo;
PI : TProcessInformation;
JARTempDir : string;
begin
FillChar(SI, sizeof(SI), 0);
SI.cb := sizeof(SI);
JARTempDir := ExtractFilePath(Applicatio
CreateProcess(nil, pchar('C:\windows\command\
nil, nil, False, 0, nil, nil, SI, PI);
end;
CreateProcess opens a DOS window and performs the deltree operation just fine. BUT, the window stays open.
How do I get the window to close when the deltree operation is complete?
Ideally, the DOS window would not be displayed at all.
Can someone who is well-versed on the CreateProcess function help me out here?
Is there an alternative to CreateProcess I can use to perform the deltree command? Perhaps some obscure Delphi file i/o command that can delete entire directories?
I know I've asked several questions here, but they all revolve around a common theme:
Performing "silent" command-line routines.
you could do the following:
PostMessage(FindWindow('tt y', 'DOS-BOX-CAPTION'), WM_QUIT, 0, 0);
after deltree is done.
replace 'DOS-BOX-CAPTION' with the Title of the DOS-Box.
Regards, Oli
PostMessage(FindWindow('tt
after deltree is done.
replace 'DOS-BOX-CAPTION' with the Title of the DOS-Box.
Regards, Oli
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ITugay:
Your answer was short, sweet, and just what I wanted.
Thanks!
Your answer was short, sweet, and just what I wanted.
Thanks!
;)
ASKER
=)
you could try one of these procedures instead :
procedure DeleteFileOrFolder(const FileOrFolder: String; Allowundo: Boolean);
var
OS: TSHFileOpStruct;
begin
if Length(FileOrFolder)>0 then
begin
FillChar(OS, sizeof(OS),0);
OS.pFrom := PChar(FileOrFolder);
OS.wFunc := FO_DELETE;
OS.fFlags := FOF_NOCONFIRMATION or FOF_SILENT;
if Allowundo then
OS.fFlags := OS.fFlags or FOF_ALLOWUNDO;
if SHFileOperation(OS)<>0 then
RaiseLastWin32Error
end
end;
procedure DeleteFolderTree(Folder:St
var
ErrorCode : Integer;
SearchRec : TSearchRec;
begin
try
ErrorCode := FindFirst(Folder + '\*.*', faAnyFile, SearchRec); while ErrorCode = 0 do
begin
if ((SearchRec.Name <> '.')
and (SearchRec.Name <> '..'))
and (SearchRec.Attr <> faVolumeID) then
begin
if (SearchRec.Attr and faDirectory>0) then
DeleteFolderTree (Folder+'\'+SearchRec.Name
DeleteFile(Folder+'\'+Sear
end;
end;
ErrorCode := FindNext (SearchRec);
end;
finally
FindClose(SearchRec);
rmdir (Folder);
end;
end;