Hives are the main sections of the registry and all begin with the word HKEY. - HKEY_LOCAL_MACHINE - HKEY_CURRENT_USER - HKEY_USER
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/Entries are name/data pairs. There can be many values in a key. The (Default) value corresponds to the Key, the rest are their own value pairs.
depends: |
|
---|
salt.modules.reg.
Registry
¶Delay usage until this module is used
salt.modules.reg.
broadcast_change
()¶Refresh the windows environment.
Returns: | True if successful, otherwise False |
---|---|
Return type: | bool |
CLI Example:
salt '*' reg.broadcast_change
salt.modules.reg.
delete_key_recursive
(hive, key, use_32bit_registry=False)¶New in version 2015.5.4.
Delete a registry key to include all subkeys.
Parameters: |
|
---|---|
Returns: | A dictionary listing the keys that deleted successfully as well as those that failed to delete. |
Return type: |
The following example will remove salt
and all its subkeys from the
SOFTWARE
key in HKEY_LOCAL_MACHINE
:
CLI Example:
salt '*' reg.delete_key_recursive HKLM "SOFTWARE\salt"
salt.modules.reg.
delete_value
(hive, key, vname=None, use_32bit_registry=False)¶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
salt.modules.reg.
key_exists
(hive, key, use_32bit_registry=False)¶Check that the key is found in the registry. This refers to keys and not value/data pairs.
Parameters: | |
---|---|
Returns: | True if found, otherwise False |
Return type: |
CLI Example
salt '*' reg.key_exists HKLM "SYSTEM\CurrentControlSet\Services\Tcpip"
salt.modules.reg.
list_keys
(hive, key=None, use_32bit_registry=False)¶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\Python
salt.modules.reg.
list_values
(hive, key=None, use_32bit_registry=False, include_default=True)¶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"
salt.modules.reg.
read_value
(hive, key, vname=None, use_32bit_registry=False)¶Reads a registry value entry or the default value for a key.
Parameters: |
|
---|---|
Returns: |
If vname is not passed:
|
Return type: |
CLI Example:
salt '*' reg.read_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version
salt.modules.reg.
set_value
(hive, key, vname=None, vdata=None, vtype=u'REG_SZ', use_32bit_registry=False, volatile=False)¶Sets a registry value entry or the default value for a key.
Parameters: |
|
---|---|
Returns: | True if successful, otherwise False |
Return type: |
CLI Example:
salt '*' reg.set_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version 2015.5.2
This function is strict about the type of vdata. For instance the next example will fail because vtype has a value of REG_SZ and vdata has a type of int (as opposed to str as expected).
CLI Example:
salt '*' reg.set_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version \\
vtype=REG_SZ vdata=0
However, this next example where vdata is properly quoted should succeed.
CLI Example:
salt '*' reg.set_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version \\
vtype=REG_SZ vdata="'0'"
An example of using vtype REG_BINARY is as follows:
CLI Example:
On a Linux master, the `!!binary` needs to be single quoted
On a Windows master, the `!!binary` to be double quoted
salt '*' reg.set_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version vtype=REG_BINARY vdata='!!binary d2hhdCdzIHRoZSBwb2ludA=='
An example of using vtype REG_MULTI_SZ is as follows:
CLI Example:
salt '*' reg.set_value HKEY_LOCAL_MACHINE "SOFTWARE\Salt" version vtype=REG_MULTI_SZ vdata="[a,b,c]"