editing the registry from a batch script

  • Thread starter Thread starter Peter T.
  • Start date Start date
P

Peter T.

Does anyone know hor to add or change an entry in the
register using a batch file. In other words I want ot
change an environment variable without using the GUI.

Thanks

Peter
 
A VBS file (VB Script) would be more useful.

Dim WshShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment\Path", <your path statement goes here>, "REG_SZ"

Set WshShell = Nothing

The above example will allow you to change the PATH environment variable,
via script. If you need to change a different environment variable, then
you need to change the corresponding values. Values for "Machine wide"
variables are in the

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment

branch of the Registry. Per user settings are in:

HKEY_CURRENT_USER\Environment
 
This depends on when you want it executed, and whether its in
HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER

For a value that's in Local Machine, in Regedit, go to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Create a new String value with whatever name you want, and then modify its
properties to read REGEDIT.EXE /S <path to REG file>

For a HKEY_CURRENT_USER value, do the same but use

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

If its a restriction that needs to be put in place in HKEY_CURRENT_USER, the
above method may not work.
 
Back
Top