コード例 #1
0
def find_exe_in_registry(keys):
    if not keys:
        return ""
    try:
        from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
    except ImportError:
        from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
    import shlex
    command = ""
    for path in keys:
        try:
            key = OpenKey(HKEY_LOCAL_MACHINE, path)
            command = QueryValue(key, "")
            break
        except OSError:
            try:
                key = OpenKey(HKEY_CURRENT_USER, path)
                command = QueryValue(key, "")
                break
            except OSError:
                pass
    else:
        return ""

    if not command:
        return ""

    return shlex.split(command)[0]
コード例 #2
0
def python_home():
	# Running 32 bit we prefer a Python in Wow6432Node if it exists:
	import platform, os
	if os.name == "java":
		# When running JyNI we cannot use platform.architecture(),
		# because it tries to load ctypes which crashes exactly due
		# to the 64 bit vs 32 bit issue we want to avoid here.
		# Note that platform.architecture() works well with plain
		# Jython, because if it cannot find ctypes at all it performs
		# some fallback.
		from java.lang import System
		arch = System.getProperty("sun.arch.data.model")+"bit"
	else:
		arch = platform.architecture()[0]
	if arch == "32bit":
		try:
			return QueryValue(HKEY_CURRENT_USER, key32)
		except WindowsError:
			pass
		try:
			return QueryValue(HKEY_LOCAL_MACHINE, key32)
		except WindowsError:
			pass
		if platform.uname()[4].endswith('64'):
			# Running 32 bit on a 64 bit platform we abort here
			return
	try:
		return QueryValue(HKEY_CURRENT_USER, key)
	except WindowsError:
		pass
	try:
		return QueryValue(HKEY_LOCAL_MACHINE, key)
	except WindowsError:
		pass
コード例 #3
0
    def _find_exe_in_registry(self):
        try:
            from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
        except ImportError:
            from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
        import shlex
        keys = (r"SOFTWARE\Classes\FirefoxHTML\shell\open\command",
                r"SOFTWARE\Classes\Applications\firefox.exe\shell\open\command")
        command = ""
        for path in keys:
            try:
                key = OpenKey(HKEY_LOCAL_MACHINE, path)
                command = QueryValue(key, "")
                break
            except OSError:
                try:
                    key = OpenKey(HKEY_CURRENT_USER, path)
                    command = QueryValue(key, "")
                    break
                except OSError:
                    pass
        else:
            return ""

        if not command:
            return ""

        return shlex.split(command)[0]
コード例 #4
0
ファイル: qad_msg.py プロジェクト: resistor4u/QAD
def qadShowPluginHelp(section="", filename="index", packageName=None):
    """
   show a help in the user's html browser.
   per conoscere la sezione/pagina del file html usare internet explorer,
   selezionare nella finestra di destra la voce di interesse e leggerne l'indirizzo dalla casella in alto.
   Questo perché internet explorer inserisce tutti i caratteri di spaziatura e tab che gli altri browser non fanno.
   """
    try:
        source = ""
        if packageName is None:
            import inspect

            source = inspect.currentframe().f_back.f_code.co_filename
        else:
            source = sys.modules[packageName].__file__
    except:
        return

    # initialize locale
    userLocaleList = QSettings().value("locale/userLocale").split("_")
    language = userLocaleList[0]
    region = userLocaleList[1] if len(userLocaleList) > 1 else ""

    path = QDir.cleanPath(os.path.dirname(source) + "/help/help")
    helpPath = path + "_" + language + "_" + region  # provo a caricare la lingua e la regione selezionate

    if not os.path.exists(helpPath):
        helpPath = path + "_" + language  # provo a caricare la lingua
        if not os.path.exists(helpPath):
            helpPath = path + "_en"  # provo a caricare la lingua inglese
            if not os.path.exists(helpPath):
                return

    helpfile = os.path.join(helpPath, filename + ".html")
    if os.path.exists(helpfile):
        url = "file:///" + helpfile

        if section != "":
            url = url + "#" + urllib.quote(section.encode("utf-8"))

        # la funzione QDesktopServices.openUrl in windows non apre la sezione
        if platform.system() == "Windows":
            import subprocess
            from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValue

            # In Py3, this module is called winreg without the underscore

            with OpenKey(HKEY_CURRENT_USER, r"Software\Classes\http\shell\open\command") as key:
                cmd = QueryValue(key, None)

            if cmd.find('"%1"') >= 0:
                subprocess.Popen(cmd.replace("%1", url))
            else:
                if cmd.find("%1") >= 0:
                    subprocess.Popen(cmd.replace("%1", '"' + url + '"'))
                else:
                    subprocess.Popen(cmd + ' "' + url + '"')
        else:
            QDesktopServices.openUrl(QUrl(url))
コード例 #5
0
def findgrcompiler():
    global grcompiler
    if sys.platform == 'win32':
        if getattr(sys, 'frozen', None):
            grcompiler = os.path.join(sys._MEIPASS, 'grcompiler.exe')
            return grcompiler
        try:
            from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
            node = "Microsoft\\Windows\\CurrentVersion\\Uninstall\\Graphite Compiler_is1"
            if sys.maxsize > 1 << 32:
                r = OpenKey(HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Wow6432Node\\" + node)
            else:
                r = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\" + node)
            p = QueryValue(r, "InstallLocation")
            grcompiler = os.path.join(p, "GrCompiler.exe")
        except WindowsError:
            for p in os.environ['PATH'].split(';'):
                a = os.path.join(p, 'grcompiler.exe')
                if os.path.exists(a):
                    grcompiler = a
                    break
    elif sys.platform == 'darwin' and getattr(sys, 'frozen', None):
        grcompiler = os.path.join(sys._MEIPASS, 'grcompiler')
        return grcompiler
    else:
        for p in os.environ['PATH'].split(':'):
            a = os.path.join(p, "grcompiler")
            if os.path.exists(a):
                grcompiler = a
                break
    return grcompiler
コード例 #6
0
ファイル: driver.py プロジェクト: uchuugaka/jellypy
def _find_chrome_in_registry():
    from _winreg import OpenKey, QueryValue, HKEY_CURRENT_USER
    path = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"

    try:
        key = OpenKey(HKEY_CURRENT_USER, path)
        install_dir = QueryValue(key, "InstallLocation")
    except OSError.WindowsError:
        return ""

    return os.path.join(install_dir, "chrome.exe")
コード例 #7
0
ファイル: win.py プロジェクト: joamatab/mimeopen
def user_current_editor(ext):
    """get the usr current editor
    @params:
        ext -- file extention
    @return
        progid -- program progid
    """
    try:
        key = OpenKey(HKEY_CLASSES_ROOT, ext)
        return QueryValue(key, None)
    except WindowsError:
        return None
コード例 #8
0
ファイル: Util.py プロジェクト: wangyangkobe/liukun
 def register(self):
     key = OpenKey(
         HKEY_CURRENT_USER,
         r"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced")
     url = "{}module=register&p_name={}".format(self.baseUrl,
                                                self.projectName)
     response = urllib2.urlopen(url).read()
     try:
         res = json.loads(response)
         try:
             print "QueryValue: %s" % QueryValue(key, "ID")
             self.id = QueryValue(key, "ID")
             self.p_name = QueryValue(key, "P_NAME")
         except Exception, _e:
             self.id = res['ID']
             self.p_name = res['P_NAME']
             SetValue(key, "ID", REG_SZ, self.id)
             SetValue(key, "P_NAME", REG_SZ, self.p_name)
     except Exception, _e:
         self.id = ''
         self.p_name = ''
コード例 #9
0
def qadShowPluginHelp(section="", filename="index", packageName=None):
    """
   show a help in the user's html browser.
   per conoscere la sezione/pagina del file html usare internet explorer,
   selezionare nella finestra di destra la voce di interesse e leggerne l'indirizzo dalla casella in alto.
   Questo perché internet explorer inserisce tutti i caratteri di spaziatura e tab che gli altri browser non fanno.
   """
    try:
        source = ""
        if packageName is None:
            import inspect
            source = inspect.currentframe().f_back.f_code.co_filename
        else:
            source = sys.modules[packageName].__file__
    except:
        return

    # initialize locale
    userLocaleList = QSettings().value("locale/userLocale").split("_")
    language = userLocaleList[0]
    region = userLocaleList[1] if len(userLocaleList) > 1 else ""

    path = QDir.cleanPath(os.path.dirname(source) + "/help/help")
    helpPath = path + "_" + language + "_" + region  # provo a caricare la lingua e la regione selezionate

    if not os.path.exists(helpPath):
        helpPath = path + "_" + language  # provo a caricare la lingua
        if not os.path.exists(helpPath):
            helpPath = path + "_en"  # provo a caricare la lingua inglese
            if not os.path.exists(helpPath):
                return

    helpfile = os.path.join(helpPath, filename + ".html")
    if os.path.exists(helpfile):
        url = "file:///" + helpfile

        if section != "":
            url = url + "#" + urllib.quote(section.encode('utf-8'))

        # la funzione QDesktopServices.openUrl in windows non apre la sezione
        if platform.system() == "Windows":
            import subprocess
            from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValue
            # In Py3, this module is called winreg without the underscore

            with OpenKey(HKEY_CURRENT_USER,
                         r"Software\Classes\http\shell\open\command") as key:
                cmd = QueryValue(key, None)

            if cmd.find("\"%1\"") >= 0:
                subprocess.Popen(cmd.replace("%1", url))
            else:
                if cmd.find("%1") >= 0:
                    subprocess.Popen(cmd.replace("%1", "\"" + url + "\""))
                else:
                    subprocess.Popen(cmd + " \"" + url + "\"")
        else:
            QDesktopServices.openUrl(QUrl(url))
コード例 #10
0
def get_install_path():
    if sys.maxsize > 2**32:
        return sys.exec_prefix  #We're running in a 64bit process

    #We're 32 bit so see if there's a 64bit install
    path = r'SOFTWARE\Python\PythonCore\2.7'

    from _winreg import OpenKey, QueryValue
    from _winreg import HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY

    try:
        with OpenKey(HKEY_LOCAL_MACHINE, path, 0,
                     KEY_READ | KEY_WOW64_64KEY) as key:
            return QueryValue(key, "InstallPath").strip(
                os.sep)  #We have a 64bit install, so return that.
    except:
        return sys.exec_prefix  #No 64bit, so return 32bit path
コード例 #11
0
ファイル: winconfig.py プロジェクト: jsanchez91/iteexe
 def __getInstallDir(self):
     """
     Returns the path to where we were installed
     """
     from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
     try:
         exeKey = None
         softwareKey = None
         try:
             softwareKey = OpenKey(HKEY_LOCAL_MACHINE, 'SOFTWARE')
             exeKey = OpenKey(softwareKey, 'exe')
             return Path(QueryValue(exeKey, ''))
         finally:
             if exeKey:
                 exeKey.Close()
             if softwareKey:
                 softwareKey.Close()
     except WindowsError:
         return Path('')
コード例 #12
0
ファイル: Utility.py プロジェクト: eaglegis/CPTB
    def get_install_path():
        """ Return 64bit python install path from registry (if installed and registered),
            otherwise fall back to current 32bit process install path.
        """
        if sys.maxsize > 2**32:
            return sys.exec_prefix  # We're running in a 64bit process

        # We're 32 bit so see if there's a 64bit install
        path = r'SOFTWARE\Python\PythonCore\2.7'

        from _winreg import OpenKey, QueryValue
        from _winreg import HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY

        try:
            with OpenKey(HKEY_LOCAL_MACHINE, path, 0,
                         KEY_READ | KEY_WOW64_64KEY) as key:
                return QueryValue(key, "InstallPath").strip(
                    os.sep)  # We have a 64bit install, so return that.
        except Exception:
            return sys.exec_prefix  # No 64bit, so return 32bit path
コード例 #13
0
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 + '\\')
コード例 #14
0
ファイル: win.py プロジェクト: joamatab/mimeopen
def get_direct_progids(ext):
    """get all direct program ids
    notice under the first level of the ext registry

    @params:
        ext -- file extention
    @return
        name, progid, command
    """
    import re

    key = OpenKey(HKEY_CLASSES_ROOT, None)
    key_no = QueryInfoKey(key)[0]

    # get all sub keys
    all_keys = []
    for index in xrange(key_no):
        all_keys.append(EnumKey(key, index))

    # check if the default program already in list
    key = OpenKey(HKEY_CLASSES_ROOT, ext)
    progids = [QueryValue(key, None)]

    logger.debug('default progid: %s', progids)

    # get backup programs
    try:
        progid = QueryValueEx(key, 'backup')[0]
    except WindowsError:
        progid = ''

    logger.debug('backup progid: %s', progid)

    progids.append(progid)

    key_no = QueryInfoKey(key)[0]
    for index in xrange(key_no):
        _id = EnumKey(key, index)
        if _id in all_keys:
            progids.append(_id)

    logger.debug('assic progid: %s', progids)

    filter_func = (lambda ext_:
                   (ext_.endswith(ext) or ext_.endswith(ext.upper())) and
                   (ext_ != ext and ext_ != ext.upper()))
    progids.extend(filter(filter_func, all_keys))

    logger.debug('related progid: %s', progids)

    exes = []
    for progid in progids:
        name = get_prog_name(progid)
        command = get_prog_command(progid)
        if name and command:
            exes.append((name, progid, command))
        if command and not name:
            match = re.search(u'.+\\\\(.+)\\\\(\w+)\.exe',
                              command,
                              flags=re.IGNORECASE)
            if match:
                name = match.group(2)
                exes.append((name, progid, command))
    return exes
コード例 #15
0
ファイル: mywebbrowser.py プロジェクト: jsanchez91/iteexe
        windows_version = QueryValueEx(winKey, val)[0]
        #Solo funciona si es Windows 10
        if 'Windows 10' in windows_version:
            register('microsoft-edge', None, MicrosoftEdge())
        winKey.Close()

        key = OpenKey(HKEY_LOCAL_MACHINE,
                      r'SOFTWARE\Clients\StartMenuInternet')
        i = 0
        while True:
            try:
                bkey_name = EnumKey(key, i)
            except:
                break
            bkey = OpenKey(key, bkey_name)
            bpath = QueryValue(bkey, r'shell\open\command')
            bname = QueryValue(bkey, '')
            register(bname, None, BackgroundBrowser(bpath.strip('"')))
            bkey.Close()
            i = i + 1
    except:
        pass
    finally:
        if key:
            key.Close()
#
# Platform support for MacOS
#

if sys.platform == 'darwin':
    # Adapted from patch submitted to SourceForge by Steven J. Burr
コード例 #16
0
 def test_simple_write(self):
     from _winreg import SetValue, QueryValue, REG_SZ
     value = "Some Default value"
     SetValue(self.root_key, self.test_key_name, REG_SZ, value)
     assert QueryValue(self.root_key, self.test_key_name) == value
コード例 #17
0
        winKey = OpenKey( HKEY_LOCAL_MACHINE , winKey)
        windows_version = QueryValueEx(winKey,val)[0]
        #Solo funciona si es Windows 10
        if 'Windows 10' in windows_version:
            register('microsoft-edge', None, MicrosoftEdge())
        winKey.Close()
        
        key = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Clients\StartMenuInternet')
        i = 0
        while True:
            try:
                bkey_name = EnumKey(key, i)
            except:
                break
            bkey = OpenKey(key, bkey_name)
            bpath = QueryValue(bkey, r'shell\open\command')
            bname = QueryValue(bkey, '')
            register(bname, None, BackgroundBrowser(bpath.strip('"')))
            bkey.Close()
            i = i + 1
    except:
        pass
    finally:
        if key:
            key.Close()
#
# Platform support for MacOS
#

if sys.platform == 'darwin':
    # Adapted from patch submitted to SourceForge by Steven J. Burr
コード例 #18
0
def get_reg_HKLM(subkey):
    # QueryValue always returns a string. It is OK for our use
    try:
        return QueryValue(HKEY_LOCAL_MACHINE, subkey)
    except WindowsError:
        return None