All notes
WindowsRegistry

Intro

reg command

ss64.com: reg.

REG QUERY [ROOT\]RegKey /v ValueName [/s]
REG QUERY [ROOT\]RegKey /ve  --This returns the (default) value
   
REG ADD [ROOT\]RegKey /v ValueName [/t DataType] [/S Separator] [/d Data] [/f]
REG ADD [ROOT\]RegKey /ve [/d Data] [/f]  -- Set the (default) value

REG DELETE [ROOT\]RegKey /v ValueName [/f]
REG DELETE [ROOT\]RegKey /ve [/f]  -- Remove the (default) value
REG DELETE [ROOT\]RegKey /va [/f]  -- Delete all values under this key

REG COPY  [\\SourceMachine\][ROOT\]RegKey [\\DestMachine\][ROOT\]RegKey

REG EXPORT [ROOT\]RegKey FileName.reg
REG IMPORT FileName.reg
REG SAVE [ROOT\]RegKey FileName.hiv
REG RESTORE \\MachineName\[ROOT]\KeyName FileName.hiv

REG LOAD KeyName FileName
REG UNLOAD KeyName

REG COMPARE [ROOT\]RegKey [ROOT\]RegKey [/v ValueName] [Output] [/s]
REG COMPARE [ROOT\]RegKey [ROOT\]RegKey [/ve] [Output] [/s]

---------------

/v: Value.
/e: Default value.
/s: Query all subkeys and values. If there is no /ve, then /s is set by default.

/d Data   : The actual data to store as a "String", integer etc
/t DataType  : REG_SZ (default) | REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
/f        : Force an update without prompting "Value exists, overwrite Y/N
"
\\Machine : Name of remote machine - omitting defaults to current machine. Only HKLM and HKU are available on remote machines.

/S Separator : Character to use as the separator in REG_MULTI_SZ values, the default is "\0" 

/reg:32   : Force REG.exe to write to the 32-bit registry location
/reg:64   : Force REG.exe to write to the 64-bit registry location
ROOT:
  HKLM = HKey_Local_machine (default)
  HKCU = HKey_current_user
  HKU  = HKey_users
  HKCR = HKey_classes_root

DataTypes

MicrosoftSupport: Definition of Registry Value Data Types.

baiduBaike. 其中“SZ”是“String Zero”的缩写,匈牙利命名法,表示null结尾的字符串变量。REG_SZ型注册表值项的名称是长度固定的文本字符串,最大长度不能超过255个字符,它的数据不限长度。


:: Query a specified value
reg query "HKCU\Control Panel\Desktop" /v wallpaper
:: HKEY_CURRENT_USER\Control Panel\Desktop
::     wallpaper    REG_SZ

:: Query the default value
reg query "HKCU\Control Panel\Desktop" /ve
:: HKEY_CURRENT_USER\Control Panel\Desktop
::     (默认)    REG_SZ    (数值未设置)

:: Query all the subset. /s is by default.
reg query "HKCU\Control Panel\Desktop"

:: Deletes the Registry value "Testvalue" under "Test" on the remote machine "RemoteSystem".
reg delete \\RemoteSystem\HKLM\Software\Test /v Testvalue

:: Adds the value "Testdata" to the key "Test" that is of type reg_binary and contains the data "ffffff".
reg add HKLM\Software\Test /v Testdata /t REG_BINARY /d ffffff

Get and Set PATH from registry

SO: how to update path variable permanently from CMD.


:: Get system PATH setting
reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path
:: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
::    Path    REG_EXPAND_SZ    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files (x86)\WinSCP\

:: Get current user's PATH setting
reg query "HKCU\Environment" /v Path
:: HKEY_CURRENT_USER\Environment
::    Path    REG_SZ    C:\MinGW\msys\1.0\bin;C:\Users\me\AppData\Local\Programs\Python\Python35\Scripts\;C:\Users\me\AppData\Local\Programs\Python\Python35\;C:\Users\me\proGreen\emacs-24.5-bin-i686-mingw32\bin;C:\Program Files\Git\cmd;C:\Users\me\proGreen\conemu;

Setting system PATH needs elevated admin rights, while setting current user's PATH does not.

Remember: broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.

StackOverflow: tools to send wm-settingchange message. This tiny utility (wprefresh.exe), which seems to do the trick: manually change HKCU\Control Panel\Desktop\Wallpaper and run wprefresh, then the new wallpaper becomes visible.

Registry FAQ

Remove Unchecked Items from MSConfig

PCWorld article. Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\MSConfig\startupreg. Remember to export and backup registry before editing.