Raikan
Raikan

Reputation: 45

REG command after SET is "unknown" in DOS/Windows batch file (.BAT)

In my batch file I started to use variables and suddenly the following commands do not work anymore.

Here is the part of my code with the problem

SET "path=MyPath"
REG ADD "HKCU\Software\ETC\ETC" /f /v "MyRegNameA" /t REG_SZ /d "%path%\ETC\"
REG ADD "HKCU\Software\ETC\ETC" /f /v "MyRegNameB" /t REG_SZ /d "%path%"
PAUSE
START "" "%path%\MyProgram.exe"  

This code works without the SET... and of course with MyPath instead of %path%. Error Message is:

The command "REG" is either spelled wrong or couldn't be found

I previously found how to use Variables here: stackEx.SetVariables To my knowledge I am doing it exactly as supposed, and I couldn't find specific help so far.

Upvotes: 2

Views: 497

Answers (1)

Magoo
Magoo

Reputation: 79982

path is a logical name, but it's not a good name to use as it is assigned by Windows.

path is a semicolon-separated list of the directories that Windows uses to find programs. When you change it, Windows can no longer find reg.exe since reg.exe is not in mypath.

Simply choose another name - don't use path. If you enter set at the prompt, you will see a list of many of the variables that are established by Windows. Simple rule - don't use any of them for user-variables.

Upvotes: 5

Related Questions