Possible Duplicate:
How do I create a Windows Batch file that does not show the Command Prompt when executed?

I want to create a shortcut on my taskbar that sets an environment variable and then launches a program. Currently my shortcut goes to a .bat file with these lines:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

but that leaves a CMD window open for the duration of the program that's launched (in this case Visual Studio). Is there a way I can do this without a CMD window opening or at least without it staying open?

I don't want to set the environment variable on my machine generally, just when I run this program.


marked as duplicate by Hello71, Nifle, Sathyajith Bhat Jul 12 '11 at 4:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Not an exact duplicate question, but the answer is the same. – Hello71 Jul 11 '11 at 17:02
  • Can you update your selected answer? Is it possible and very simple to do.. batch file: line 1: set var1=hello.txt line 2: start "test" notepad.exe "%~dp0%var1%" – Kody Brown Jan 12 '15 at 6:10

The linked answer is right, that you can't using batch files.

I would create a batch file that runs a PowerShell script (PowerShell is here to stay at least for the foreseeable future). Here is the batch file:

powershell c:\temp\OpenVisualStudio.ps1

And here is the contents of your PS1 PowerShell script file:

start-process "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

Name then whatever you want, but I would name them the same (extension excepted), and put them in the same place. I wanted to combine them into one file, but it was problematic to set the variable.

I tested this, although I used it to open Word 2010.


How to run a bat file without displaying the command window:

Create a new file named 'runhidden.vbs' Edit it with a text editor and insert the following line:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

Set your shortcut to execute this:

wscript.exe runhidden.vbs yourbatfile.bat

Naturally, path names should be added to runhidden.vbs and yourbatfile.bat if required. This will execute yourbatfile.bat without showing the command window.

EDIT: To clarify "runhidden" is an entirely arbitrary name. You can name it how you want.

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