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.
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
.bat script. That script then can executes whatever commands you want. From
/Dwas NOT specified on the command line, then when
CMD.EXEstarts, it looks for the following
REG_EXPAND_SZregistry variables, and if either or both are present, they are executed first.
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
@echo off cd SOME_DIRECTORY SOME_COMMAND SOME_OTHER_COMMAND 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.