?
Solved

how to close console window

Posted on 1998-08-11
5
Medium Priority
?
328 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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