Python _winreg.QueryValue() Examples

The following are 9 code examples of _winreg.QueryValue(). 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: UnrealManagerWindows.py    From ue4cli with MIT License 6 votes vote down vote up
def getGenerateScript(self):
		
		# Under Windows, GenerateProjectFiles.bat only exists for source builds of the engine
		batFile = self.getEngineRoot() + '\\Engine\\Build\\BatchFiles\\GenerateProjectFiles.bat'
		if os.path.exists(batFile):
			return batFile
		
		# For versions of the engine installed using the launcher, we need to query the shell integration
		# to determine the location of the Unreal Version Selector executable, which generates VS project files
		try:
			key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, 'Unreal.ProjectFile\\shell\\rungenproj\\command')
			if key:
				command = winreg.QueryValue(key, None)
				if len(command) > 0:
					
					# Write the command to run UnrealVersionSelector.exe to our own batch file
					customBat = os.path.join(self._customBatchScriptDir(), 'GenerateProjectFiles.bat')
					Utility.writeFile(customBat, command.replace('"%1"', '%1') + '\r\n')
					return customBat
		except:
			pass
		
		raise UnrealManagerException('could not detect the location of GenerateProjectFiles.bat or UnrealVersionSelector.exe.\nThis typically indicates that .uproject files are not correctly associated with UE4.') 
Example #2
Source File: DS301_index.py    From CANFestivino with GNU Lesser General Public License v2.1 6 votes vote down vote up
def get_acroversion():
    " Return version of Adobe Acrobat executable or None"
    import _winreg
    adobesoft = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe')
    for index in range(_winreg.QueryInfoKey(adobesoft)[0]):
        key = _winreg.EnumKey(adobesoft, index)
        if "acrobat" in key.lower():
            acrokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key)
            for index in range(_winreg.QueryInfoKey(acrokey)[0]):
                numver = _winreg.EnumKey(acrokey, index)
                try:
                    res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver))
                    return res
                except:
                    pass
    return None 
Example #3
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def GetVlcPath():
    """
    Tries to get the path of VLC's executable through querying the Windows
    registry.
    Not querying HKLM\Software\VideoLAN\VLC to avoid multiple queries
    neccessary due to registry virtualization on 64 bit systems.
    """
    try:
        path = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\VLC.OPENFolder\shell\Open\command").split("\"")[1]
    except:
        return None

    if os.path.exists(path):
            return path
    else:
        return None 
Example #4
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def GetIrfanViewPath(self):
        """
        Get the path of IrfanView's install-dir through querying the
        Windows registry.
        """
        try:
            iv_reg = _winreg.OpenKey(
                _winreg.HKEY_CLASSES_ROOT,
                "\\Applications\\i_view32.exe\\shell\\open\\command"
            )
            IrfanViewPath =_winreg.QueryValue(iv_reg, None)
            _winreg.CloseKey(iv_reg)
            IrfanViewPath=IrfanViewPath[:-5]
            IrfanViewPath=IrfanViewPath[1:-1]
        except WindowsError:
            IrfanViewPath = None
        return IrfanViewPath 
Example #5
Source File: util.py    From trelby with GNU General Public License v2.0 5 votes vote down vote up
def getWindowsPDFViewer():
    try:
        import _winreg

        # HKCR/.pdf: gives the class of the PDF program.
        # Example : AcroRead.Document or FoxitReader.Document

        key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ".pdf")
        pdfClass = _winreg.QueryValue(key, "")

        # HKCR/<class>/shell/open/command: the path to the PDF viewer program
        # Example: "C:\Program Files\Acrobat 8.0\acroread.exe" "%1"

        key2 = _winreg.OpenKey(
            _winreg.HKEY_CLASSES_ROOT, pdfClass + r"\shell\open\command")

        # Almost every PDF program out there accepts passing the PDF path
        # as the argument, so we don't parse the arguments from the
        # registry, just get the program path.

        path = _winreg.QueryValue(key2, "").split('"')[1]

        if fileExists(path):
            return path
    except:
        pass

    return None

# get a windows environment variable in its native unicode format, or None
# if not found 
Example #6
Source File: Utils.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def get_registry_app_path(key,filename):
	if not winreg:
		return None
	try:
		result=winreg.QueryValue(key,"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s.exe"%filename[0])
	except WindowsError:
		pass
	else:
		if os.path.isfile(result):
			return result 
Example #7
Source File: Utils.py    From royal-chaos with MIT License 5 votes vote down vote up
def get_registry_app_path(key,filename):
	if not winreg:
		return None
	try:
		result=winreg.QueryValue(key,"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s.exe"%filename[0])
	except WindowsError:
		pass
	else:
		if os.path.isfile(result):
			return result 
Example #8
Source File: install.py    From anima with MIT License 5 votes vote down vote up
def install_scripts():
    """installs javascripts for python
    """
    # find photoshop install dir
    reg_key_path = r"SOFTWARE\Adobe\Photoshop"
    with OpenKey(HKEY_LOCAL_MACHINE, reg_key_path) as k:
        version_sub_key_name = EnumKey(k, 0)
        version_sub_key = OpenKey(k, version_sub_key_name)
        install_path = QueryValue(version_sub_key, "ApplicationPath")

    # now copy all the files under scripts folder to
    # photoshop/Presets/Scripts path
    photoshop_scripts_path = os.path.normpath(
        os.path.join(
            install_path, 'Presets', 'Scripts'
        )
    )
    print(photoshop_scripts_path)

    here = os.path.dirname(__file__)
    scripts_folder = os.path.join(here, 'scripts')

    for root, dirs, files in os.walk(scripts_folder):
        for file_ in files:
            file_path = os.path.join(root, file_)
            shutil.copy(
                os.path.normpath(file_path),
                photoshop_scripts_path + '\\'
            ) 
Example #9
Source File: util.py    From ironpython2 with Apache License 2.0 4 votes vote down vote up
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, basestring):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = _winreg.HKEY_CLASSES_ROOT
                hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = _winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            if os.path.basename(dll) != os.path.basename(pythoncom.__file__):
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print "Can't import win32com.shell - no idea if you are an admin or not?"
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print "Registering engine", filename
#       print cmd
    rc = os.system(cmd)
    if rc:
        print "Registration command was:"
        print cmd
        raise RuntimeError("Registration of engine '%s' failed" % filename)