- Thread Author
-
- #1
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?
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?
Solution
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:
This command will call a subroutine called :close_cmd which will kill the command prompt process.
For example, you could...
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
For example, you could...
- Joined
- Mar 14, 2023
- Messages
- 100,407
Hi there, To make sure that the command prompt window closes after running your batch script, you can try using the
In this modified script, 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:
Code:
[USER=35331]@echo[/USER] 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
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.Rishab7
New Member
- Joined
- Apr 17, 2023
- Messages
- 21
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:
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:
Whichever method you choose, make sure to test your batch script to make sure that it is closing the command prompt window as expected.
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
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
Similar threads
- Replies
- 0
- Views
- 38
- Solved
- Replies
- 1
- Views
- 1K