Windows 10 Windows batch scrip - Window does not close after script

clawwd

New Member
Hi Guys,

I have a one to run by you.

I have a simple Windows batch script I run in the morning that basically opens various programs I use for the day. Lazy doing this...yup LOL.

Issue is the command prompt window that pops up never closes after the script is run.

I have tried ending the script with both commands below and neither closes the window.

exit

cd "C:\Windows\System32\"
taskkill /IM cmd.exe /f


Here is a sample of what the batch script looks like except with one of the above commands added to the end:

@echo Starting Outlook
@echo off
cd "C:\Program Files\Microsoft Office\root\Office16\"
start OUTLOOK.EXE
if %errorlevel%==0 echo Successfully Launched Application

@echo Starting Temp Notepad
@echo off
cd "C:\Users\jbarber\Desktop\
start temp.txt
if %errorlevel%==0 echo Successfully Launched Application
echo.


Any ideas and thanks for your help?
 
Hi there,

To make sure that the command prompt window closes after running your batch script, you can try using the `start` command with the `/B` option. This will start the program without opening a new command prompt window.

Here's an example of how you can modify your script:

```
@echo off

echo Starting Outlook
cd "C:\Program Files\Microsoft Office\root\Office16\"
start /B OUTLOOK.EXE
if %errorlevel%==0 echo Successfully Launched Application

echo Starting Temp Notepad
cd "C:\Users\jbarber\Desktop\
start /B temp.txt
if %errorlevel%==0 echo Successfully Launched Application

exit
```

In this modified script, the `start /B` command is used to start the programs without opening a new command prompt window. After running the batch script, the command prompt window should close automatically.

Note: Make sure to remove the `@echo` command at the beginning of each line, as using `@echo off` disables the command prompt from displaying the commands being executed.

I hope this helps! Let me know if you have any further questions.
 
o close the command prompt window after a batch script is run, you can use the following command:

start /b cmd.exe /c "your_batch_script_name.bat"
The /b switch tells Windows to start the batch script in a new window and then immediately close the original window.

For example, if your batch script is called my_batch_script.bat, you would use the following command to start it and close the command prompt window:

start /b cmd.exe /c my_batch_script.bat
You can also use the following command to close the command prompt window from within your batch script:

Code:
call :close_cmd

:close_cmd
taskkill /IM cmd.exe /f
This command will call a subroutine called :close_cmd which will kill the command prompt process.

For example, you could add the following lines to the end of your batch script to close the command prompt window:

Code:
call :close_cmd

:close_cmd
taskkill /IM cmd.exe /f
Whichever method you choose, make sure to test your batch script to make sure that it is closing the command prompt window as expected.
 
Back
Top