0

Is there a way to append a Registry key with a batch file? To be clear, I don't want to replace the key, I want to add to it.

Example:

Key Location:   HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 

Change:         C:\Windows;C:\Java

To:             C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT

It's a REG_EXPAND_SZ, so [~] won't work, unless I'm doing it wrong. https://msdn.microsoft.com/en-us/library/aa371168(VS.85).aspx

James C.
  • 11,076
  • 2
  • 29
  • 37
lolok
  • 1
  • Please take also a look on [What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) There can be read why it is better to use command __SetX__ instead of `reg add` to add folder path to __user__ or __system__ `PATH` or add any other environment variable to __user__ or __system__ environment variables list. __SetX__ adds the environment variable automatically as `REG_EXPAND_SZ` if the variable value to add contains `%`, otherwise it adds it as `REG_SZ`. – Mofi Jun 01 '18 at 15:28

1 Answers1

0

Save this to something.reg. Execute this with double click and you will set changes. This is maybe overwriting but I think this is better idea.

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT /t REG_SZ /f
James C.
  • 11,076
  • 2
  • 29
  • 37
  • I found a PowerShell script that worked. Thanks for your help. [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files (x86)\CFLAT", [EnvironmentVariableTarget]::Machine) – lolok Jun 01 '18 at 19:20