Merge pull request #6222 from ranl/develop

reg module/state support for all Value Types
This commit is contained in:
David Boucha 2013-07-18 00:46:15 -07:00
commit feabb34f5a
2 changed files with 13 additions and 6 deletions

View File

@ -79,27 +79,33 @@ def read_key(hkey, path, key):
return False
def set_key(hkey, path, key, value):
def set_key(hkey, path, key, value, vtype='REG_DWORD'):
'''
Set a registry key
vtype: http://docs.python.org/2/library/_winreg.html#value-types
CLI Example::
salt '*' reg.set_key HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version' '0.97'
salt '*' reg.set_key HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version' '0.97' REG_DWORD
'''
registry = Registry()
hkey2 = getattr(registry, hkey)
# fullpath = '\\\\'.join([path, key])
try:
_type = getattr(_winreg, vtype)
except AttributeError:
return False
try:
# handle = _winreg.OpenKey(hkey2, fullpath, 0, _winreg.KEY_ALL_ACCESS)
handle = _winreg.OpenKey(hkey2, path, 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, key, 0, _winreg.REG_DWORD, value)
_winreg.SetValueEx(handle, key, 0, _type, value)
_winreg.CloseKey(handle)
return True
except Exception:
handle = _winreg.CreateKey(hkey2, path)
_winreg.SetValueEx(handle, key, 0, _winreg.REG_DWORD, value)
_winreg.SetValueEx(handle, key, 0, _type, value)
_winreg.CloseKey(handle)
return True

View File

@ -23,7 +23,7 @@ def _parse_key(key):
return hive, path, key
def present(name, value):
def present(name, value, vtype='REG_DWORD'):
'''
Set a registry entry
@ -32,6 +32,7 @@ def present(name, value):
'HKEY_CURRENT_USER\\SOFTWARE\\Salt\\version':
reg.present:
- value: 0.15.3
- vtype: REG_SZ
'''
ret = {'name': name,
@ -51,7 +52,7 @@ def present(name, value):
return ret
# configure the key
ret['result'] = __salt__['reg.set_key'](hive, path, key, int(value))
ret['result'] = __salt__['reg.set_key'](hive, path, key, value, vtype)
if not ret:
ret['changes'] = {}
ret['comment'] = 'could not configure the registry key'