Close DOS window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
TipMark
Posts: 9
Joined: 12 May 2017 19:49

Close DOS window

#1 Post by TipMark » 14 May 2017 15:44

I have some DOS commands that run (backup files) and then the last command is to open an
Excel file.

What happens is the DOS window stays open (in the background) and when the Excel file is closed
the DOS window finally closes on its own.

Is it possible to have the DOS window close automatically, right after the Excel file open command is issued?

After the file open command I have 'Exit'.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Close DOS window

#2 Post by ShadowThief » 14 May 2017 15:59

Sure, just add && exit /b to the line where you call the Excel file. For instance,

Code: Select all

@echo off
pause
start "" excel.exe && exit /b

TipMark
Posts: 9
Joined: 12 May 2017 19:49

Re: Close DOS window

#3 Post by TipMark » 15 May 2017 16:02

ShadowThief wrote:Sure, just add && exit /b to the line where you call the Excel file. For instance,

Code: Select all

@echo off
pause
start "" excel.exe && exit /b


Thanks Shadow. I just tried out your code and am not getting the results I hoped for.

This is my line to open the file (before adding your code):

"c:\Program Files\MS Office yada yada....\excel.exe" d:\Mom\2017.xls

If I add your code (&& exit /b):
1. at end of my code, there is no effect.
2. in the middle, it then asks to confirm each file overwrite,
is not opening the Excel file (but opening Excel) and not closing window!
3. at beginning after excel.exe, it closes window but doesn't open the Excel file.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Close DOS window

#4 Post by aGerman » 15 May 2017 16:16

Because you didn't use the START command Excel was run synchronoulsy. That should have been the reason why the batch window didn't close. Thus, I don't think you would even need EXIT /B. However you still need to run Excel asynchronously using START.

Code: Select all

start "" "excel.exe" "d:\Mom\2017.xls"

Don't omit the empty pair of quotation marks at the beginning.

Steffen

TipMark
Posts: 9
Joined: 12 May 2017 19:49

Re: Close DOS window

#5 Post by TipMark » 15 May 2017 17:32

aGerman wrote:Because you didn't use the START command Excel was run synchronoulsy. That should have been the reason why the batch window didn't close. Thus, I don't think you would even need EXIT /B. However you still need to run Excel asynchronously using START.

Code: Select all

start "" "excel.exe" "d:\Mom\2017.xls"

Don't omit the empty pair of quotation marks at the beginning.

Steffen


Thanks Steffen. Well I think I am making progress. :)

I tried the start "" suggestion.
The window is closing now but another unexpected behavior has surfaced.
Excel is opening with a pop-up for a password (as is normal for this file).
BUT... even with the cursor blinking in the field waiting for a password to be entered,
I can't enter anything in the box!

I must first click on the border of the box, before it will allow me to enter a password!

This is happening with a shortcut I created on the desktop to launch the .bat file.

If I launch the .bat file from Total Commander, the DOS window pops up, runs a few commands and disappears.
Then, Total Commander remains on top of the Excel program that launched.
When I close Total Commander, the password field is ready to accept a password.

I hope this is clear.

It will be desirable to run the .bat file from the desktop, have the Excel password field pop-up and be ready to accept the password immediately.

carlsomo
Posts: 91
Joined: 02 Oct 2012 17:21

Re: Close DOS window

#6 Post by carlsomo » 09 Jun 2017 15:12

TipMark,

Assuming you wish to run some batch code and then, when finished start a specific excel spreadsheet and have the batch window closed with the excel window 'on top' ??

You could try this:

RunMyBatchThenOpenMyExcelFile.bat (make a shortcut to this file and set to run minimized under shortcut properties)

Code: Select all

@echo off
call MyBatchCodeFile.bat &rem run your batch code in a visible cmd window
start "" "excel.exe" "d:\Mom\2017.xls"


Sorry to hear about Foxidrive, a very good contributer....

Carl

Post Reply