views:

1975

answers:

4

For the moment my batch file look like this:

myprogram.exe param1

The program start but the Dos Windows still open... how can I close it?

+4  A: 

You can use the exit keyword. Here is an example from one of my batch file:

start myProgram.exe param1
exit
Daok
+6  A: 

Look at the START command, you can do this:

START rest-of-your-program-name

For instance, this batch-file will wait until notepad exits:

@echo off
notepad c:\test.txt

However, this won't:

@echo off
start notepad c:\test.txt
Lasse V. Karlsen
+2  A: 

You should try this. It starts the program with no window. It actually flashes up for a second but goes away fairly quickly.

start "name" /B myprogram.exe param1
Chris Dail
+2  A: 

From my own question:

start /b myProgram.exe params...

works if you start the program from an existing DOS session.

If not, call a vb script

wscript.exe invis.vbs myProgram.exe %*

The Windows Script Host Run() method takes:

  • intWindowStyle : 0 means "invisible windows"
  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish

Here is invis.vbs:

set args = WScript.Arguments
num = args.Count

if num = 0 then
    WScript.Echo "Usage: [CScript | WScript] invis.vbs aScript.bat <some script arguments>"
    WScript.Quit 1
end if

sargs = ""
if num > 1 then
    sargs = " "
    for k = 1 to num - 1
     anArg = args.Item(k)
     sargs = sargs & anArg & " "
    next
end if

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
VonC