Solved

how to close console window

Posted on 1998-08-11
5
316 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
  • 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 50 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now