20

For whatever reason, on a specific machine my cmd process doesn't inherit its environment variables from the parent process which launched it. Instead it reverts back to the "default" environment settings, like it was launched via explorer.

A simple way to demonstrate this is to open a command-prompt and then run set Path=C:\Windows\System32\, followed by launching another cmd process from the same prompt. The variable can then be viewed by running set Path.

It should be "C:\Windows\System32" (inherited from the launching process) but on my machine it's reverted back to my environment default.

You should see something like this: Working command prompt

I instead get the following: CMD breaking the rules

What could be causing this? It seems to break all the rules around how environment variables work and it only affects this one machine.

2
  • 6
    I wouldn’t recommend using path as the discriminating test for something like this, as it’s an ubiquitous symbol that could easily be reset/hijacked by some tool, utility or setting. You should consider using some other unique/improbable symbol (like zzMyTestSymbol) as an additional control test. Dec 2, 2019 at 22:25
  • 1
    .. as borne out by the answer! Dec 3, 2019 at 15:40

2 Answers 2

27

The problem is caused by the command processor's AutoRun setting. This little "feature" of the command-line lets you configure a script to run every time a CMD process starts.

In my case, something (possibly an install of NVMW) had registered a script which assigned a completely new Path value, ignoring any existing value entirely.

Removing the HKCU\Software\Microsoft\Command Processor\Autorun value restored the command-line to its normal behaviour.

1

Use the /d option of cmd.exe to skip Autorun commands from the registry. No need to remove the Autorun key.

C:\> cmd /? | findstr uto
/D      Disable execution of AutoRun commands from registry (see below)
    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

More 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

        and/or

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

You must log in to answer this question.

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