Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From How to add a program to a list with right click button?, I could add "command" button to open command line prompt using right click.

I normally open the command line prompt to use Visual Studio tools, so running 'vcvarsall.bat' in the command line is the first thing that I normally do.

How can I automatize this? I mean, how can I run a batchfile automatically to setup environment whenever a command line shell is invoked?

Visual Studio provides a shortcut in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2010\Visual Studio Tools named 'Visual Studio Command Prompt (2010)' to do the setup environment for me. I thought about running this instead of command line, but the start in directory is fixed to the directory in VS2010, so I don't think that's a good idea.

enter image description here

share|improve this question

3 Answers 3

up vote 1 down vote accepted

If you want a shortcut that will open a command prompt, run a batch file and then stay in the command prompt you can use CMD's /K switch:

/K - Carries out the command specified by string but remains

So create a shortcut (either on the desktop, or via the right-click setup mentioned in the answer to the other question you linked) and set the command/target to something like:

cmd /K "c:\PathToBatch\vcvarsall.bat"

share|improve this answer

Right Click on My Computer -> Properties -> Advanced System Settings.

Choose the Advanced tab and then click Environment Variables.

Edit and /or add User variables.

Now, whenever you open a shell, these varaibles will be set.

share|improve this answer

Based on techie007's answer, I could use regedt32 to change the registry to run the batchfile with /K option.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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