示例#1
0
def clean(reg_vars):
    """
    Make sure the key does NOT exist
    """
    try:
        if reg_util.key_exists(hive=reg_vars.hive, key=reg_vars.key):
            reg_util.delete_key_recursive(hive=reg_vars.hive, key=reg_vars.key)
        yield
    finally:
        if reg_util.key_exists(hive=reg_vars.hive, key=reg_vars.key):
            reg_util.delete_key_recursive(hive=reg_vars.hive, key=reg_vars.key)
示例#2
0
def test_pkg__get_reg_software_noremove():
    search = "test_pkg_noremove"
    key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{}".format(
        search)
    win_reg.set_value(hive="HKLM", key=key, vname="DisplayName", vdata=search)
    win_reg.set_value(hive="HKLM",
                      key=key,
                      vname="DisplayVersion",
                      vdata="1.0.0")
    win_reg.set_value(hive="HKLM",
                      key=key,
                      vname="NoRemove",
                      vtype="REG_DWORD",
                      vdata="1")
    try:
        result = win_pkg._get_reg_software()
        assert isinstance(result, dict)
        found = False
        search = "test_pkg"
        for item in result:
            if search in item:
                found = True
        assert found is True
    finally:
        win_reg.delete_key_recursive(hive="HKLM", key=key)
        assert not win_reg.key_exists(hive="HKLM", key=key)
示例#3
0
 def test_delete_key_recursive_key_not_found(self):
     """
     Test the delete_key_recursive function when the passed key to delete is
     not found.
     """
     self.assertFalse(win_reg.key_exists(hive="HKLM", key=FAKE_KEY))
     self.assertFalse(win_reg.delete_key_recursive(hive="HKLM", key=FAKE_KEY))
示例#4
0
 def test_key_exists_non_existing(self):
     '''
     Tests the key exists function using a non existing registry key
     '''
     self.assertEqual(
         win_reg.key_exists(
             hive='HKLM',
             key=FAKE_KEY
         ),
         False
     )
示例#5
0
 def test_key_exists_existing(self):
     '''
     Tests the key exists function using a well known registry key
     '''
     self.assertEqual(
         win_reg.key_exists(
             hive='HKLM',
             key='SOFTWARE\\Microsoft'
         ),
         True
     )
示例#6
0
def reset(reg_vars):
    """
    Create an existing key for testing
    """
    try:
        if not reg_util.value_exists(
                hive=reg_vars.hive, key=reg_vars.key, vname=reg_vars.vname):
            reg_util.set_value(
                hive=reg_vars.hive,
                key=reg_vars.key,
                vname=reg_vars.vname,
                vdata=reg_vars.vdata,
            )
        yield
    finally:
        if reg_util.key_exists(hive=reg_vars.hive, key=reg_vars.key):
            reg_util.delete_key_recursive(hive=reg_vars.hive, key=reg_vars.key)
示例#7
0
 def test_key_exists_non_existing(self):
     """
     Tests the key_exists function using a non existing registry key
     """
     self.assertFalse(win_reg.key_exists(hive="HKLM", key=FAKE_KEY))
示例#8
0
 def test_key_exists_existing(self):
     """
     Tests the key_exists function using a well known registry key
     """
     self.assertTrue(
         win_reg.key_exists(hive="HKLM", key="SOFTWARE\\Microsoft"))
示例#9
0
文件: win_reg.py 项目: fake-name/salt
        key (str): The key to check in

        vname (str): The name of the value/data pair you're checking

        use_32bit_registry (bool): Look in the 32bit portion of the registry

    Returns:
        bool: True if exists, otherwise False

    Usage:

        .. code-block:: python

            import salt.utils.win_reg as reg
            reg.key_exists(hive='HKLM', key='SOFTWARE\\Microsoft')
    '''
    local_hive = _to_unicode(hive)
    local_key = _to_unicode(key)
    local_vname = _to_unicode(vname)

    registry = Registry()
    try:
        hkey = registry.hkeys[local_hive]
    except KeyError:
        raise CommandExecutionError("Invalid Hive: {0}".format(local_hive))
    access_mask = registry.registry_32[use_32bit_registry]

    try:
        handle = win32api.RegOpenKeyEx(hkey, local_key, 0, access_mask)
    except win32api.error as exc: