Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Batch file that runs cmd.exe, a command, and then stays open at prompt

I have a set of environmental variables that I have to run before I can run other operations. I have a batch file for these but when I run the batch file it closes at the end. Is there something I can add so it will not close so I can continue to run other operations in the command prompt without writing them into the batch file script itself?

I eventually would like to have a batch file for each operation but I have a lot of different operations I need to run. So for now this will help to avoid the manual work of opening the batch file and copying and pasting the variables into a new command prompt window every time I go to run a new operation.

share|improve this question

marked as duplicate by heavyd, slhck Oct 29 '12 at 20:10

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.

How are you opening the command-prompt/running the batch-file. There are at least three ways that this can be solved depending on your circumstances. – Synetech Oct 29 '12 at 18:37
I am running the batch file from windows explorer window. – Shenanigans Oct 29 '12 at 18:45
up vote 1 down vote accepted

If you need some environment variables set every time that you use the command-prompt, then there are three ways that you can do so:

  • Create the environment variables at the system level, then they will always be available at the command-prompt. You can do this for either a user or the the whole system.

  • Instead of running the batch file directly, create a shortcut to the command-interpreter, passing it the batch-file as an argument, and using the /k switch to keep it open after running:

    %comspec% /k c:\stuff\setenvs.bat
  • You can set the Autorun key to automatically run a command whenever you open a command-prompt. Again, you can set it for just a user or the whole system:

    [HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
share|improve this answer
Awesome, I got the /K switch working. Thank you so much. You just made my life soo much easier. – Shenanigans Oct 29 '12 at 18:59

Run command prompt with the /K switch. This prevents it from closing after the .bat has run


share|improve this answer

Not the answer you're looking for? Browse other questions tagged .