Manage the Windows registry
Hives are the main sections of the registry and all begin with the word HKEY.
Keys are the folders in the registry. Keys can have many nested subkeys. Keys can have a value assigned to them under the (Default)
When passing a key on the CLI it must be quoted correctly depending on the backslashes being used (\
vs \\
). The following are valid methods of passing the the key on the CLI:
"SOFTWARE\Python"
'SOFTWARE\Python'
(will not work on a Windows Master)SOFTWARE\\Python
Values or Entries are the name/data pairs beneath the keys and subkeys. All keys have a default name/data pair. The name is (Default)
with a displayed value of (value not set)
. The actual value is Null.
Example
The following example is an export from the Windows startup portion of the registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "RTHDVCPL"="\"C:\\Program Files\\Realtek\\Audio\\HDA\\RtkNGUI64.exe\" -s" "NvBackend"="\"C:\\Program Files (x86)\\NVIDIA Corporation\\Update Core\\NvBackend.exe\"" "BTMTrayAgent"="rundll32.exe \"C:\\Program Files (x86)\\Intel\\Bluetooth\\btmshellex.dll\",TrayApp"
In this example these are the values for each:
HKEY_LOCAL_MACHINE
SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
depends: |
|
---|
Refresh the windows environment.
Note
This will only effect new processes and windows. Services will not see the change until the system restarts.
Returns: | True if successful, otherwise False |
---|---|
Return type: | bool |
CLI Example:
salt '*' reg.broadcast_change
New in version 2015.5.4.
Delete a registry key to include all subkeys and value/data pairs.
Parameters: |
hive (str) -- The name of the hive. Can be one of the following
|
---|---|
Returns: |
|
Return type: | dict |
CLI Example:
The following example will remove
delete_me
and all its subkeys from theSOFTWARE
key inHKEY_LOCAL_MACHINE
:salt '*' reg.delete_key_recursive HKLM SOFTWARE\\delete_me
Delete a registry value entry or the default value for a key.
Parameters: |
|
---|---|
Returns: |
True if successful, otherwise False |
Return type: |
CLI Example:
salt '*' reg.delete_value HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version'
Import registry settings from a Windows REG
file by invoking REG.EXE
.
New in version 2018.3.0.
Parameters: |
|
---|---|
Returns: |
True if successful, otherwise an error is raised |
Return type: | |
Raises: |
|
CLI Example:
salt machine1 reg.import_file salt://win/printer_config/110_Canon/postinstall_config.reg
Check that the key is found in the registry. This refers to keys and not value/data pairs.
Parameters: | |
---|---|
Returns: |
True if exists, otherwise False |
Return type: |
CLI Example:
salt '*' reg.key_exists HKLM SOFTWARE\Microsoft
Enumerates the subkeys in a registry key or hive.
Parameters: |
|
---|---|
Returns: |
A list of keys/subkeys under the hive or key. |
Return type: |
CLI Example:
salt '*' reg.list_keys HKLM 'SOFTWARE'
Enumerates the values in a registry key or hive.
Parameters: |
|
---|---|
Returns: |
A list of values under the hive or key. |
Return type: |
CLI Example:
salt '*' reg.list_values HKLM 'SYSTEM\\CurrentControlSet\\Services\\Tcpip'
Reads a registry value entry or the default value for a key. To read the default value, don't pass vname
Parameters: |
|
---|---|
Returns: |
A dictionary containing the passed settings as well as the value_data if successful. If unsuccessful, sets success to False. bool: Returns False if the key is not found If vname is not passed:
|
Return type: |
CLI Example:
The following will get the value of the
version
value name in theHKEY_LOCAL_MACHINE\\SOFTWARE\\Salt
keysalt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version'
CLI Example:
The following will get the default value of the
HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt
keysalt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt'
Sets a value in the registry. If vname
is passed, it will be the value for that value name, otherwise it will be the default value for the specified key
Parameters: |
|
---|---|
Returns: |
True if successful, otherwise False |
Return type: |
CLI Example:
This will set the version value to 2015.5.2 in the SOFTWARESalt key in the HKEY_LOCAL_MACHINE hive
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version' '2015.5.2'
CLI Example:
This function is strict about the type of vdata. For instance this example will fail because vtype has a value of REG_SZ and vdata has a type of int (as opposed to str as expected).
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'str_data' 1.2
CLI Example:
In this next example vdata is properly quoted and should succeed.
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'str_data' vtype=REG_SZ vdata="'1.2'"
CLI Example:
This is an example of using vtype REG_BINARY.
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'bin_data' vtype=REG_BINARY vdata='Salty Data'
CLI Example:
An example of using vtype REG_MULTI_SZ is as follows:
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'list_data' vtype=REG_MULTI_SZ vdata='["Salt", "is", "great"]'
© 2019 SaltStack.
Licensed under the Apache License, Version 2.0.
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.reg.html