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

x
?
Solved

Hiding a Dos window

Posted on 1998-10-06
16
Medium Priority
?
199 Views
Last Modified: 2010-04-06
If someone can help me, I need a function in delphi, that execute DOS programs , but doesn't appear the DOS window.
0
Comment
Question by:sabadao
[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
  • 5
  • 5
  • 3
  • +1
16 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1342048
Hi,
Is something like this what you're looking for?:
 
  WinExec( 'command.exe /c ' + MyDOSCommand, SW_HIDE );

/// John
0
 

Accepted Solution

by:
kashif063098 earned 80 total points
ID: 1342049
ans is coming
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342050
Why do you propose an answer w/o being sure you know the answer??? You cannot just answer the question and go write your code... Maybe someone else wants to answer the question...

//Vik
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!

 

Expert Comment

by:kashif063098
ID: 1342051
you can use either Winexec() or CreateProcess().
the easiest function to use is Winexec() but its usually for 16bit compatibility.
Any how you can use
WinExec() in following way

procedure RunMyDosApp;
Var
  ApplicationToRun :string;
begin

  ApplicationToRun := 'C:\Winnt\system32\command.com';{you should put the path and                                                                                                                                                        the name of application to run}
  if (WinExec(ApplicationToRun, SW_HIDE) < 31) then
       dwErrorCode := GetLastError;
end;

feel free to ask ?
0
 

Expert Comment

by:kashif063098
ID: 1342052
T A K E  A C H I L L  P I L !! --->VIK..
0
 

Author Comment

by:sabadao
ID: 1342053
Thanks, but I have another problem: I have two DOS programs to be executed, and I need to know when one finished to  then I can execute the other.
Tanks for the help
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342054
YOU BETTER TAKE A CHILL PAL...ALRIGHT???
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342055
Hello sabadao!

here is a function to use with so it waits until the external app finishes...
-----------
function WinExecAndWait(const FileName, Params: string; WindowState: word): Boolean;
var
{$IFDEF WIN32}
   SUInfo: TStartupInfo;
   ProcInfo: TProcessInformation;
   CmdLine: string;
{$ELSE}
   InstanceID: THandle;
   Buff: array[0..255] of char;
{$ENDIF}
begin
  {$IFDEF WIN32}
   (* enclose the filename in quotes in case it contains spaces *)
   CmdLine := Format('"%s" %s', [FileName, Params]);
   FillChar(SUInfo, SizeOf(SUInfo), #0);
   with SUInfo do begin
      cb := SizeOf(SUInfo);
      dwFlags := STARTF_USESHOWWINDOW;
      wShowWindow := WindowState
   end;
   Result := CreateProcess(nil, pChar(CmdLine), nil, nil, false, (CREATE_NEW_CONSOLE or       NORMAL_PRIORITY_CLASS), nil, pChar(ExtractFilePath(FileName)), SUInfo, ProcInfo);
   if Result then
      WaitForSingleObject(ProcInfo.hProcess, INFINITE)
{$ELSE}
   StrPCopy(Buff, Format('%s %s', [FileName, Params]));
   InstanceID := WinExec(Buff, WindowState);
   if (InstanceID < 32) then  (* a value of less than 32 is bad *)
      Result := false
   else begin
      Result := true;
      repeat
         Application.ProcessMessages
      until (Application.Terminated or (GetModuleUsage(InstanceID) = 0))
   end
{$ENDIF}
end;
--------
Regards,
Viktor Ivanov
0
 

Expert Comment

by:kashif063098
ID: 1342056
grow up ..vi
why you are making big deal out of it ...
you need some points let me know  
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342057
nope....no need of that... I'm sorry of what I said but just wanted to tell you that it's not a good habit... Sorry if I've created a conflict...

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1342058
Hey guys! Calm down.
Viktor, don't get upset because Kashif doesn't know the mode d'emploi in X-X. He'll learn.
Kashif, sometimes feelings come up when people think they have, or have, better solutions than the one provided, or when cultures clash. Thats just the way it is. Nothing personal, since we don't really know eachother.
The code of honour in X-X is, atleast by my standards: treat anybody the way you want to be treated by them. Join the discussion, don't devastate it. We are all friends here.

Otherwise, keep up the good work!

Now is a good time to puke after listening to all that crap... ;-)

/// John, self-elected prefect of X-X.
0
 

Expert Comment

by:kashif063098
ID: 1342059
viktor i am new to this exchange ..and i have seen people locking my favorite questions but never said any thing ...i thought may be it is the way every one should be helping others ...  
may be this explains my point view and apology ..

see yoo all
erajoj --> i really believe in your X-X theory, and apperciate your concern ...thanks
0
 

Author Comment

by:sabadao
ID: 1342060
But, this code, when the Dos windows is hide, doesn't no when de application finished to run to run the other application. And how I can destroy de hide window when de application is finished.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342061
same here.,,, 10x John :-)
I believe we are all frineds in here...so i apologies for that...especially to kashif :-)

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1342062
Hi Sabadao,
Try this out:

  sMyDOSCommand := 'dir c:\*.* > c:\dir.txt'; // redirect the dir output to file

  // start the command...
  // "command.com /c" runs a DOS command and terminates

  WinExecAndWait( 'command.com /c' , sMyDOSCommand, SW_HIDE );

  // the command is done and the window is gone...

Type "command /?" at the DOS prompt to get a description of the command switches.

/// John
0
 

Author Comment

by:sabadao
ID: 1342063
John tanke for the help, but this command :WinExecAndWait( 'command.com /c' , sMyDOSCommand, SW_HIDE ); didn't work only with DIR, CLS, but didn't with executable command.
I am doing something wrong or have another way to run and terminate a dos Program?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

649 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