Many python developers think of registry keys as if they were python keys in a dictionary which is not the case. The windows registry is broken down into the following components:
This is the top level of the registry. They all begin with HKEY.
- HKEY_CLASSES_ROOT (HKCR)
- HKEY_CURRENT_USER(HKCU)
- HKEY_LOCAL MACHINE (HKLM)
- HKEY_USER (HKU)
- HKEY_CURRENT_CONFIG
Hives contain keys. These are basically the folders beneath the hives. They can contain any number of subkeys.
When passing the hivekey values they must be quoted correctly depending on the
backslashes being used (\
vs \\
). The way backslashes are handled in
the state file is different from the way they are handled when working on the
CLI. The following are valid methods of passing the hivekey:
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 taken 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
Value:
RTHDVCPL
, NvBackend
, and BTMTrayAgent
salt.states.reg.
absent
(name, vname=None, use_32bit_registry=False)¶Ensure a registry value is removed. To remove a key use key_absent.
Parameters: |
|
---|---|
Returns: | A dictionary showing the results of the registry operation. |
Return type: |
CLI Example:
'HKEY_CURRENT_USER\\SOFTWARE\\Salt': reg.absent - vname: versionIn the above example the value named
version
will be removed from the SOFTWARE\Salt key in the HKEY_CURRENT_USER hive. Ifvname
was not passed, the(Default)
value would be deleted.
salt.states.reg.
key_absent
(name, use_32bit_registry=False)¶New in version 2015.5.4.
Ensure a registry key is removed. This will remove the key, subkeys, and all value entries.
Parameters: |
|
---|---|
Returns: | A dictionary showing the results of the registry operation. |
Return type: |
CLI Example:
The following example will delete the
SOFTWARE\DeleteMe
key in theHKEY_LOCAL_MACHINE
hive including all its subkeys and value pairs.remove_key_demo: reg.key_absent: - name: HKEY_CURRENT_USER\SOFTWARE\DeleteMeIn the above example the path is interpreted as follows:
HKEY_CURRENT_USER
is the hiveSOFTWARE\DeleteMe
is the key
salt.states.reg.
present
(name, vname=None, vdata=None, vtype='REG_SZ', use_32bit_registry=False)¶Ensure a registry key or value is present.
Parameters: |
|
---|---|
Returns: | A dictionary showing the results of the registry operation. |
Return type: |
Example
The following example will set the (Default)
value for the
SOFTWARE\\Salt
key in the HKEY_CURRENT_USER
hive to
2016.3.1
:
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
reg.present:
- vdata: 2016.3.1
Example
The following example will set the value for the version
entry under
the SOFTWARE\\Salt
key in the HKEY_CURRENT_USER
hive to
2016.3.1
. The value will be reflected in Wow6432Node
:
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
reg.present:
- vname: version
- vdata: 2016.3.1
In the above example the path is interpreted as follows:
HKEY_CURRENT_USER
is the hiveSOFTWARE\\Salt
is the keyvname
is the value name (‘version’) that will be created under the keyvdata
is the data that will be assigned to ‘version’
Example
Binary data can be set in two ways. The following two examples will set
a binary value of Salty Test
no_conversion:
reg.present:
- name: HKLM\SOFTWARE\SaltTesting
- vname: test_reg_binary_state
- vdata: Salty Test
- vtype: REG_BINARY
conversion:
reg.present:
- name: HKLM\SOFTWARE\SaltTesting
- vname: test_reg_binary_state_with_tag
- vdata: !!binary U2FsdHkgVGVzdA==\n
- vtype: REG_BINARY
Example
To set a REG_MULTI_SZ
value:
reg_multi_sz:
reg.present:
- name: HKLM\SOFTWARE\Salt
- vname: reg_multi_sz
- vdata:
- list item 1
- list item 2
Docs for previous releases are available on readthedocs.org.
Latest Salt release: 2018.3.2