-1

Where does one set environment settings (notice, I'm not saying just variables) that control the behaviour of cmd you get when starting with win-r? So, Win-r cmd.

Specifically, what I want to know is ... what do I need to do, if I have a bat file which I want started every time that cmd is started ... where to put it? And what to set somewhere?

2 Answers 2

1

For Microsoft's cmd, use AutoRuns.

Environment variables are irrelevant to this. (And there's nothing aside from environment variables that is conventionally named environment settings, so that distinction is meaningless.)

Under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor (for everyone machine-wide) or the HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor (for just one user) key in the registry, add a value named AutoRun. It must be a REG_SZ or REG_EXPAND_SZ value. Microsoft's command processor will read the string every time that it starts up, and run the commands in the string before doing anything else.

For JP Software's TCC/LE use TCSTART.BTM.

TCC doesn't have a local-machine-versus-per-user configuration mechanism, although it's fairly simple to achieve that with some creative use of the %USERPROFILE% environment variable. There's just the one script.

Caveat

These commands are executed by every instance of the command processor that you start, whether you run it from WinKey+r, or an desktop shortcut names the command processor as the program to run, or a program "shells out" by invoking the command processor to do stuff. The local machine value will be used by any service that uses the command processor. You can break things quite seriously, and introduce major security hazards, if you do anything non-trivial, such as commands that change directory, generate output, run external commands, or modify the filesystem, with these mechanisms.

For best results, don't do this. Pass whatever you want to do in this script to the command processor on its command line, directly from the WinKey+r edit field, instead.

Further reading

3
  • a) environment settings ... doskey aliases hanging in the background.
    – Rook
    Jan 9, 2012 at 20:53
  • Those are not conventionally named "environment settings".
    – JdeBP
    Jan 10, 2012 at 10:41
  • Nor did I say they were ...
    – Rook
    Jan 10, 2012 at 20:50
0

You can try changing the ComSpec Environment variable to point to the batch file you want to run.

For example, setting ComSpec to "C:\Windows\System32\cmd.exe" "C:\path\to\your\batchFile.bat" /K will cause the command prompt to run the batch file and remain open afterwards.

NB: You can set the Environment Variable as follows:
Right click on My Computer -> Properties -> Advanced (tab) -> Environment Variables (button)

2
  • … which has the side-effect of breaking every program that expects COMSPEC to point to a command processor, as it conventionally does.
    – JdeBP
    Jan 9, 2012 at 14:03
  • well, rather unfortunately so... Your answer is better, in my opinion. I'd forgotten about that feature when I was writing my answer. Jan 9, 2012 at 17:37

You must log in to answer this question.

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