salt.modules.reg

Manage the Windows registry

Hives

Hives are the main sections of the registry and all begin with the word HKEY. - HKEY_LOCAL_MACHINE - HKEY_CURRENT_USER - HKEY_USER

Keys

Keys are the folders in the registry. Keys can have many nested subkeys. Keys can have a value assigned to them under the (Default)

Values or Entries

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:
  • winreg Python module
class salt.modules.reg.Registry

Delay '_winreg' usage until this module is used

salt.modules.reg.broadcast_change()

Refresh the windows environment.

salt.modules.reg.delete_key_recursive(hive, key, use_32bit_registry=False)

2015.5.4 新版功能.

Delete a registry key to include all subkeys.

参数:
  • hive --

    The name of the hive. Can be one of the following

    • HKEY_LOCAL_MACHINE or HKLM
    • HKEY_CURRENT_USER or HKCU
    • HKEY_USER or HKU
  • key -- The key to remove (looks like a path)
  • use_32bit_registry (bool) -- Deletes the 32bit portion of the registry on

64bit installations. On 32bit machines this is ignored.

返回:A dictionary listing the keys that deleted successfully as well as

those that failed to delete. :rtype: dict

The following example will remove salt and all its subkeys from the SOFTWARE key in HKEY_LOCAL_MACHINE:

CLI 范例:

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.

参数:
  • hive (str) --

    The name of the hive. Can be one of the following

    • HKEY_LOCAL_MACHINE or HKLM
    • HKEY_CURRENT_USER or HKCU
    • HKEY_USER or HKU
  • key (str) -- The key (looks like a path) to the value name.
  • vname (str) -- The value name. These are the individual name/data pairs

under the key. If not passed, the key (Default) value will be deleted.

参数:use_32bit_registry (bool) -- Deletes the 32bit portion of the registry on

64bit installations. On 32bit machines this is ignored.

返回:Returns True if successful, False if not
返回类型:bool

CLI 范例:

salt '*' reg.delete_value HKEY_CURRENT_USER 'SOFTWARE\Salt' 'version'
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.

参数:
  • hive (str) --

    The name of the hive. Can be one of the following

    • HKEY_LOCAL_MACHINE or HKLM
    • HKEY_CURRENT_USER or HKCU
    • HKEY_USER or HKU
  • key (str) -- The key (looks like a path) to the value name.
  • vname (str) -- The value name. These are the individual name/data pairs

under the key. If not passed, the key (Default) value will be returned

参数:use_32bit_registry (bool) -- Accesses the 32bit portion of the registry

on 64bit installations. On 32bit machines this is ignored.

返回:A dictionary containing the passed settings as well as the

value_data if successful. If unsuccessful, sets success to False :rtype: dict

If vname is not passed:

  • Returns the first unnamed value (Default) as a string.
  • Returns none if first unnamed value is empty.
  • Returns False if key not found.

CLI 范例:

salt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version'
salt.modules.reg.set_value(hive, key, vname=None, vdata=None, vtype='REG_SZ', use_32bit_registry=False)

Sets a registry value entry or the default value for a key.

参数:
  • hive (str) --

    The name of the hive. Can be one of the following

    • HKEY_LOCAL_MACHINE or HKLM
    • HKEY_CURRENT_USER or HKCU
    • HKEY_USER or HKU
  • key (str) -- The key (looks like a path) to the value name.
  • vname (str) -- The value name. These are the individual name/data pairs

under the key. If not passed, the key (Default) value will be set.

参数:
  • vdata (str) -- The value data to be set.
  • vtype (str) --

    The value type. Can be one of the following:

    • REG_BINARY
    • REG_DWORD
    • REG_EXPAND_SZ
    • REG_MULTI_SZ
    • REG_SZ
  • use_32bit_registry (bool) -- Sets the 32bit portion of the registry on

64bit installations. On 32bit machines this is ignored.

返回:Returns True if successful, False if not
返回类型:bool

CLI 范例:

salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version' '2015.5.2'