Getting a Macro to close a DOS window

Tezcatlipoca

Registered User.
Local time
Today, 19:35
Joined
Mar 13, 2003
Messages
246
The title pretty much says it all. I currently have a Macro in my database that, without going in to too much detail, runs a small *.bat dos program on the hard drive. The program runs fine, as does the Macro that executes it.

At the moment, once the program is run the DOS window that has finished running the program just sits on the screen until the X box in the upper right corner of the window is clicked. It's purely an aesthetic concern, but is it possible to get my Macro - once it's run the application - to close it automatically?

I've tried doing this in what I see as the simpler way (i.e. having the batch file close itself), but my DOS command of 'exit' appears to not work.
 
Why wouldn't exit work?

I just wrote a batch file as:
test.bat

contents:

dir/w
cls
exit

saved the file and ran it and it worked fine.
Otherwise you will need to use some VB API to grab the window and close it. I'd have to play around with it.

Jon
 
"Why wouldn't exit work?"

That's just it. I've no idea. My batch file runs fine, and my DOS knowledge, whilst not excessive, is good enough to know that my file contains no errors or problems. Why it runs the program then keeps the window open despite the 'exit' command is a total mystery to me.
 
Managed to solve this problem now, but I'm going to post the answer here as well just in case somebody ever has a similar problem and pulls this thread up in a search.

DOS can be controlled with the following code:

call Shell ( Environ$ ( "COMSPEC" ) & " /c c:\test.bat", vbNormalFocus)

The Environ$("COMSPEC") returns the path to Command.com on the machine and the "/c" argument makes sure that the Dos window is automatically closed when the batch file finishes executing
 

Users who are viewing this thread

Back
Top Bottom