Solved

how to close console window

Posted on 1998-08-11
5
320 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 92
TServerSocket - file via sendbuf or Text via sendtext ? 1 65
RESTRequest Parameter 4 43
firemonkey Android Listview Sort items 7 51
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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