Batch file process leaves extra command prompt open

I have this batch file and it makes a batch file in the startup folder that opens a specific URL to a website. My problem is that whenever it runs it also leaves an empty command prompt open.

The batch script runs fine and it opens the website URL with the web browser, but it just leaves an additional CMD window open that I'd like not to occur. Note: I am not asking how to run a CMD window in the background.

Here's the code:

@echo off
cd C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
echo @echo off > startup.bat
echo start (link) >> startup.bat
start startup.bat

Could someone help point out what I could change to resolve this issue?

3

2 Answers

You could use CALL and add the /MIN switch with the START command to keep it more hidden and ensure the CMD window disappears when running per the way you have the logic setup in your above example.

I made some quick adjustments and added this logic for you to have an exact example of what I used and confirmed works as you explain you need it to work.

Example Script

@echo off
CD /D C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
echo @echo off > startup.bat
echo START /MIN "" "">> startup.bat
echo EXIT /B>> startup.bat
CALL startup.bat
EXIT /B

Further Resources

2

Please take a look at the link below:

How to run a batch file without launching a "command window"?

If the link is inaccessible, one answer states to create a vbs script that contains the following:

CreateObject("Wscript.Shell").Run "your_batch_file.bat", 0, True

Where "your_batch_file.bat" is the name of your batch file.

Save the above as a visual basic script, e.g.: example.vbs and run it.

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like