Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing the DOS window within my VB code...

Status
Not open for further replies.

rahmanjan

Programmer
Apr 13, 2003
180
AU
hi all,

I am using my vb code to run a DOS window. The code is running ok and finishes. but the problem is that the screen still remains on.

My questions:

1- can i run the code without opening the DOS window? would be great!!!

2- otherwise how can close the window that is opened?

regards,

rahman
 
You could run a batch file instead of a dos session or you could do a "sendkeys" and issue the exit command to the dos window
 
Can't one change the properties of the (admittedly hypothetical) shortcut so that window closes on program close?


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Hi Tom,

yes that is what i did. But still the window doesnt close.

Let is say:

test.bat

@echo off
echo "hellow world"
exit

If i run this bat file it runs the window and automatically closes. BUT IF I RUN THE SAME BATCH FROM MY VB CODE IT DOESN'T CLOSE!!

I don't know why?


Anddy,

can you be more clear please? ;-)

regards
 
Are you using Shell? Use the c switch. To copy a bmp to the D Drive for example. This is on my machine using XP. FOr Win 9x use command.com I think.

Code:
Shell "cmd /c copy C:\windows\clouds.bmp D:\"

Will close the window after it has finished.


 
Better if you use command.com as Mosaic1 also indicated as it works with both Win98 and WinXP.
Shell "command.com /c copy C:\windows\clouds.bmp D:\"
 
You could also add vbHide to not show the window at all. i.e.

Dim a
a = Shell("command.com /c copy C:\windows\clouds.bmp D:\", vbHide)

 
Very nice ca8msm!!!

That was initially my question!!

you deserve more stars (********************) ;-)

regards

 
The reason to use the /c switch is this. You want to clean up after your program. Use vbhide and then have a look at task manager. You'll see cmd.exe is still running.



It's easy enough to find out if NT or 9x and use the correct file.

Like this:
Environ("OS")
If Right(OS, 2) = "NT" Then
use cmd
Else use command.com
End if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top