4

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

3 Answers 3

2

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"

2

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

enter image description here

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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