Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CreateProcess okay, but DOS "window" doesn't close

Posted on 2000-04-05
6
Medium Priority
?
304 Views
Last Modified: 2006-11-17
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(Application.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.
0
Comment
Question by:Tom Knowlton
[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
6 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2687253
Hi
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:String);
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,SecureDelete)           else
            DeleteFile(Folder+'\'+SearchRec.Name)
          end;
        end;
        ErrorCode := FindNext (SearchRec);
    end;
  finally
    FindClose(SearchRec);
    rmdir (Folder);
  end;
end;
0
 
LVL 1

Expert Comment

by:Oli2
ID: 2687389
you could do the following:

PostMessage(FindWindow('tty', 'DOS-BOX-CAPTION'), WM_QUIT, 0, 0);

after deltree is done.
replace 'DOS-BOX-CAPTION' with the Title of the DOS-Box.

Regards, Oli
0
 
LVL 9

Accepted Solution

by:
ITugay earned 200 total points
ID: 2689933
You may do it more easy and DOS window would not be displayed.

uses ShellApi;

procedure TFormMain.DeleteTempFolder;
.......
   ShellExecute(handle,'open','command','/c deltree /Y ' +  JARTempDir,nil,0);
end;

-------------
Igor.
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 5

Author Comment

by:Tom Knowlton
ID: 2730819
ITugay:

Your answer was short, sweet, and just what I wanted.

Thanks!
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2730922
;)
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 2730959
=)
0

Featured Post

Independent Software Vendors: 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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 …
Suggested Courses

610 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