[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to close console window

Posted on 1998-08-11
5
Medium Priority
?
330 Views
Last Modified: 2010-04-04
Hi, All.

My main program calls another DOS application by 'CreateProcess'API.
After that, the console window opens and DOS app. starts.
But I cannnot close the console window when DOS app. is over.

Please teach me how to code.

Syouchi.

0
Comment
Question by:Syouchi
[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
5 Comments
 

Author Comment

by:Syouchi
ID: 1361910
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361911
so us your code. Zif.
0
 

Author Comment

by:Syouchi
ID: 1361912
This is a part of my app.
'irp.exe' is encrypt DOS program I made.

-----------------------------------------------

function TFrCrypt.Angouka():string;
var
   CodeFile,MyPath,ComLine,
   OpenkeyPath,tmpS:string;
   SI:TStartupinfo;
   PI:TProcessInformation;
begin
   MyPath := ExtractFilePath(ParamStr(0));
   Opendialog1.InitialDir:=mypath;
   if OpenDialog1.Execute then
   begin
       CodeFile := OpenDialog1.FileName;
       Angouka:=ChangeFileExt(CodeFile,'.irp');

       IniFile:=TIniFile.Create(ChangeFileExt(ParamStr(0),'.ini'));

       OpenkeyPath:=iniFile.readString('Crypt','NkeyDir','');
       OpenkeyPath:=OpenkeyPath+'Syochi.opn';

if AnsiupperCase(ExtractFilePath(CodeFile))=AnsiupperCase(mypath) then
       CodeFile:=ExtractFilename(CodeFile);
       ComLine := 'irp.exe /c '+ OpenkeyPath +' ' + CodeFile;
       GetStartupInfo(SI);
       tmpS := MyPath + ComLine;
    CreateProcess(nil,PChar(tmpS),nil,nil,false,0,nil,nil,SI,PI);

   end;
end;
---------------------------------------------------------------


0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1361913
try this when process is finished :

CloseHandle( PI.hProcess );

maybe also CloseHandle( pi.hThread );

thus windows have to wait until Dos program is finished?

if so, try this... :

procedure ExecNewProcess(ProgramName : String);
 var
   StartInfo  : TStartupInfo;
   ProcInfo   : TProcessInformation;
   CreateOK   : Boolean;
 begin

   { fill with known state }
   FillChar(StartInfo,SizeOf(TStartupInfo),#0);
   FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
   StartInfo.cb := SizeOf(TStartupInfo);

   CreateOK := CreateProcess(nil, PChar(ProgramName), nil, nil,False,
               CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
               nil, nil, StartInfo, ProcInfo);

   { check to see if successful }
   if CreateOK then
     //may or may not be needed. Usually wait for child processes
     WaitForSingleObject(ProcInfo.hProcess, INFINITE);

// if needed and process is ended : CloseHandle....?
 end;



0
 

Author Comment

by:Syouchi
ID: 1361914
Dear ZifNab.

Your both ways lead me to success.
Thanks a lot.

Syouchi.


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

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…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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