Getting DOS session to automatically close

I'm trying to get a DOS session to close automatically in Win95, without having to set anything special in Win95 itself. Other programs do this very nicely but I haven't been able to find out how though the VC++ 5 docs. I'm currently using ShellExecute() for this purpose. I'd also like to know how to get that DOS session to remain invisible without having to resort to an invisible window setting.

Thanks in advance for your help!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RJVAuthor Commented:
Adjusted points to 100
Try to use ShellExecute(" /c ftp.exe") if you want to
ftp.exe in DOS session.
/c is auto close.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi Jackie,

That's an interesting solution. However, I keep getting this error:

    Specified COMMAND search directory bad

The path (to a batch file in this case) is ok, so this is somewhat perplexing. Meanwhile, how will things fare in the NT environment, seeing as it doesn't have a


Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

RJVAuthor Commented:
Can you post up your commands and batch file contents?
Do you give the full path in commands?
What is your DOS path? ( You can get it by typing "set" in DOS session )

This works but doesn't close:

  ShellExecute(NULL,NULL,prog,flnm+" "+cmds,wrkPath,show);


      prog = "c:\project\temp\batch.bat"
      flnm = blank
      cmds = blank
      workPath = blank
      show = (can be normal, minimzed or hide)

This gets the error without even opening the batch file itself (seen after removing the /c):

     prog = " /c c:\project\temp\batch.bat"

Note that is in the path (see below) and I've tried the above giving the specific path and even at the DOS prompt itself, with the same error. Here's the applicable parts of the evironment:


Though it never opens the batch file itself, here are its contents, which work without

   Arj a c:\work\add\test.arj c:\work\test.txt
   Arj a c:\work\add\test.arj c:\work\test1.txt

Hopes this helps! Also thanks for the extra help. I plan to increase the points as it's nice to be able to make up for extra help given for those that do make the effort.


RJVAuthor Commented:
Try to run " /kc:\project\temp\batch.bat"
If it succeed, then turn it to " /cc:\project\temp\batch.bat"

Jackie, have you tried the solution under VC++? I didn't get back earlier as today I decided to go after this and, no matter what I did, no luck. Everything works fine, but without closing the DOS session, as long as run on its own. It appears as if shelling puts you under and then it doesn't like the extra

The main problem is to get the DOS session to close automatically under Win95 which stubbornly won't collaborate so far.


RJVAuthor Commented:
You should run the " /cc:\project\temp\batch.bat" under Win95 [Start] --> [Run].
If you run it under DOS session, it will need exit twice.
Because DOS session is another, you know.

I use the solution under VC++ exactly.
But I am using the CreateProcess() instead of ShellExecute().
I don't know what is the difference about running

Now we're getting a bit closer in coding. I was actually using CreateProcess() plus ShellExecute(). I use the former to wait for an app to finish. Exactly how do you set up CreateProcess? I'll do the same here so we may nail this down.

As to two DOS sessions, I only tried it with a command line to try and find the problem. However, I believe when you launch a DOS program you automatically launch a DOS session, so maybe by using you may indeed get two of them. I could be wrong on that one, though.


RJVAuthor Commented:

Just to note that I got CreateProcess() to work, finally. The problem is that did not recognize the path given (why I don't know, as it seems to take itself back to PC or MS/DOS version 1). I made our application change to the correct path/folder and then run the batch file and all was ok.

Now I just need to find out if the operating system is Win95 or NT to switch and cmd.exe accordingly. Any tips would be greatly appreciated! As indicated, I've increased the points for your extra effort, which was vital for the solution of my problem.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.