Ok so I've started Java at school and we have to compile and run our code through the CMD (no admin privileges)(on windows 10). Every time I open CMD, I have to change the directory to the bin folder to be able to do my Java stuff. My question is: Is there any way to open the CMD so that there have already been specific commands run? i.e. when I open CMD or whatever file I create, can the directory already be set to where I want it to be (as well as a different font colour and title for the CMD window), then I can start using CMD as normal? I haven't really found any comprehensible answers anywhere.

  • 1
    For the font color, you can set that using the Application menu of the command prompt. (The icon at the upper left.) Select it, then select Defaults. Then the Colors tab, the Screen Text, then pick your color. Future command prompts will use that color.
    – Doug Deden
    Feb 12, 2019 at 0:15
  • 1
    Try this sort of solution for part of your question: superuser.com/questions/1312668/… Feb 12, 2019 at 0:17
  • And the answers to this question will help with the "can the directory already be set to where I want it to be" part. stackoverflow.com/questions/60904/…
    – Doug Deden
    Feb 12, 2019 at 0:18
  • Sure, the link I provided gives you a method to do with a simple shortcut and is easily changeable with no third party tool and no registry edits.... Just plug in the value of the path you want it to open in the Start in: field. Feb 12, 2019 at 0:21

1 Answer 1


If you want to run some commands whenever you open any Command Prompt window, you can create a HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun string variable in the Windows registry and set it to the path of a .cmd/.bat script. That script then can executes whatever commands you want. From cmd /?:

If /D was NOT specified on the command line, then when CMD.EXE starts, it looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if either or both are present, they are executed first.

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun


HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

Be forewarned: I do not actually recommend setting the AutoRun variable since it affects all cmd.exe instances and could have unexpected (and possibly confusing) side effects that will be hard to debug later if you forget that AutoRun is set in the registry.

Alternatively, if you wish to be able to double-click on an icon, execute some commands, and get an interactive Command Prompt window, then you instead can create a .cmd (or .bat) script:

@echo off

cmd /k

Double-clicking on that script will execute the specified commands, invoke a cmd.exe subshell, and leave it running waiting for additional input.


You must log in to answer this question.

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