2

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?

  • 1
  • FYI. . . How to run a batch file completely hidden\without launching a command window and how to have the command window exit once it is done running are completely different tasks. None of these answer in this possible dupe link from your comment list anything about EXIT or the other syntax I used in my below answer with this method. – Pimp Juice IT Aug 9 '16 at 5:03
  • Tbh when you edited my question you completely changed what it was asking. It leaves a window open for a reason I don't know. The 2 original windows that it ran close. Your solution helped anyway though. Not a duplicate was asking why an additional window was opening. – INTENSEFIRE Aug 9 '16 at 5:37
2

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 "" "https://google.com">> startup.bat
echo EXIT /B>> startup.bat

CALL startup.bat
EXIT /B

Further Resources

  • PIMP_JUICE_IT, flag questions as duplicates when they exist. Answering duplicate questions discourages users from looking for their answers first, and help fill the site with noise. See Meta Stack Exchange for more info. – Canadian Luke Aug 9 '16 at 4:17
  • I read it, but only one answer, and it seems to agree about duplicates, flag 'em – Canadian Luke Aug 9 '16 at 4:31
1

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.

  • 1
    Hi Kruschk, if you find a link within the site that answers the question, you should flag the question as a duplicate instead of posting the link and content as an entirely separate answer. – Canadian Luke Aug 9 '16 at 3:15
  • Hey Luke, how do I go about flagging as duplicate? I only see options relevant to spam or low-quality. I just wanted to help the guy out because I can't comment on posts that aren't my own yet! – kruschk Aug 9 '16 at 3:17
  • Clicking "Flag" just beneath the question, and choosing the "Duplicate" option. Because I already pasted the link in, you can click on the question from the list, and click Flag. – Canadian Luke Aug 9 '16 at 3:20
  • I only have the options to flag as "spam", "rude or abusive", "very low quality", or "in need of moderator intervention"! Even after googling around I can't seem to find it... – kruschk Aug 9 '16 at 3:26
  • Ok don't worry about it then – Canadian Luke Aug 9 '16 at 3:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.