Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I want a .bat file which opens a command prompt and then set my default directory also set the enviromenet variable JAVA_HOME

For now I am manually openning command prompt and then setting my project directry path and then setting the environment variable.

I am using commands as :

open cmd.exe
cd d:\Code
set JAVA_HOME=C:\Jdk.1.6

I want that when I execute the batch file that execute the commant before openning. How to do that ?

share|improve this question
there is no open command in cmd. – Endoro Apr 5 '13 at 18:26
up vote 4 down vote accepted

Assuming you want specifically a batch file to be clickable directly on Windows desktop, a simple, yet not elegant way, would be to use the following code in batch file:

@cd d:\Code
@set JAVA_HOME=C:\Jdk.1.6"
@cmd.exe /K

It will set the path and the variable, and in that context launch a nested command session with /K parameter - which will force it to wait for user input (instead of disappearing).

A more elegant solution would be to create a new shortcut on the desktop and configure it as follows:

  • Command: cmd /K set JAVA_HOME=C:\Jdk.1.6
  • Start in: d:\Code
share|improve this answer

Try this batch script:

@echo off
set "JAVA_HOME=C:\Jdk.1.6"
cd /d "d:\Code"
cmd /k
share|improve this answer
+1 as it helped in understanding /d for directory which is what i was searching for. Thanks – Anmol Saraf Oct 26 '13 at 21:56

Your Answer


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.