Reg.exe Error: Too many command-line parameters - windows

I have a command in my bat file that appends the Path environmental variable:
reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d %PATH%;"C:\Program Files\Java\jdk1.7.0_51\bin"
However, I get an error: "Error: Too many command-line parameters"
How can I successfully append without using the GUI?

the code
reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d %PATH%;"C:\Program Files\Java\jdk1.7.0_51\bin"
Should read like this
reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%PATH%";"C:\Program Files\Java\jdk1.7.0_51\bin"
If the path was all one like like this C:\windows\system32 then it would work with out editing. But if it has spaces like C:\Users\user\AppData\Roaming\Intel Corporation\ then as it has a space then cmd read's it as C:\Users\user\AppData\Roaming\Intel so you will get your error.

Related

Why are changes to the Winlogon registry being ignored by MDT TaskSequence?

I'm setting up a Task Sequence(TS) in MDT for deploying Win10 IoT Enterprise. As one of the final steps in the TS I'm trying to add AutoLogon of the user account to the registry. But when the TS finishes and I check, the changes have either not been made or they have been reset by some clean-up script.
I create a new "Run Command Line" step in the TS, right after the Install Applications step that MDT generates automatically. This step runs a script I've added to the Deploy/Scripts folder. I get no errors here, but no result either.
I've tried to export the correct registry-settings to a .reg file and use the "Run Command Line" step to import these. Again, no errors and no result.
I've moved both of these steps down in the list, so that they are the last thing the TS does. Again, no errors and no result.
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d <username>/f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d <Domain> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <password> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 500000 /f
I want the AutoLogon to be set automatically. If not, there has to be a procedure for how to set it up and that not only feels unnecessary, but is also a source of errors if its forgotten.
After more googling I finally found:
https://ccmcache.wordpress.com/2018/02/07/workaround-for-windows-10-1709-autoadminlogon-at-the-end-of-configmgr-osd-task-sequence/
Where there is a solution. An ugly one, but the only way I've found that works. So thank you to the author of this.

Correct syntax to expand the Path registry entry's value with a batch file variable value

I want to expand the Path registry variable's value with a value of a batch file variable
:: This is the content of the install.cmd
set ROOT_DIR=%~dp0%
echo %path%|find /i "%ROOT_DIR%\Tools\">nul || set path=%path%;%ROOT_DIR%\Tools\
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d %path% /f
Expected: it appends the %ROOT_DIR%\Tools to the %path% if it does not contain already, then write out the whole path to the Path Registry entry
Actual: Invalid syntax
Variation 1
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d ^%path^% /f
Result: it ignores the force switch, remove everything from the Path and overwrite it with a '/f' string
Variation 2
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d %%path%% /f
Result: it overrides the content of the Path registry entry with a "%path%" string (not with its value)
Variation 3
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d path /f
Result: it overrides the content of the Path registry entry with a "path" string (not with its value)

Batch, adding quotes to argument stops reg from working

So i tried to make a batch file that runs when a txt file is opened.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d %0 /f
So far so good. But when i open the text document theres an error due to spaces in %0.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d "%0" /f
This doesnt give me an error, but the registry value doesnt change.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d ^"%0^" /f
Same thing.
So whats my problem here?
The escape character in this case, (complete lack of consistency, I know), is the back slash:
Reg Add "HKCR\txtfile\shell\open\command" /VE /D \"%~0\" /F >Nul

Adding a directory to the system path variable through registry

I am trying to add a directory to the PATH variable in windows. This is what I am entering the command line. (Or a batch file)
#echo off
set value=%path%;%ProgramFiles%\AtomScript\
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Sessions Manager\Environment" /v Path /t REG_EXPAND_SZ /d %value% /f
And it comes up with this message
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.
What am I doing wrong?
You probably have to quote %value% (with double-quotes) because its expansion has embedded blanks for C:\Program Files, etc.
That would be
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Sessions Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%value%" /f
You can see what the actual expansions are by turning echo on in your script:
#echo on
Maybe you solved it already, but as far as I can see you also might have a misspelling in "...\Sessions Manager...". At least on my system it's "Session" without the extra s.

How to get the full path of a file properly?

I've to add a script to windows registry via command line as follow:
Reg add HKCU\Software\...\.\.. /v backUp /t REG_SZ /d "%~dp0\backUp.bat" /f
The script is called "setup.bat" it contains only the above line. BTW backUp.bat is running at the same dir as the "setup.bat" so for that i'm using %~dp0 to get the full path of the script dir. I surrounded %~dp0 by ", because some path contains spaces.. So, normally when i run i set properly the full path of the backUp.bat, whenever the script is running, but the problem is that i get a double slash before backUp.bat in my registry, look:
C:\Users\marwen\Desktop\bin\\backUp.bat
If i change the command as this:
Reg add HKCU\Software\...\.\.. /v backUp /t REG_SZ /d "%~dp0"\backUp.bat /f
Same here, the result is faulty :
C:\Users\marwen\Desktop\bin"\backUp.bat
How to solve this ?
untested but Reg add HKCU\Software\...\.\.. /v backUp /t REG_SZ /d "%~dp0backUp.bat" /f without the slash should do it.

Resources