def get_installaton_path_on_windows(fc_name):
    # tested for FreeCAD 0.18
    import itertools
    from winreg import (
        ConnectRegistry,
        HKEY_LOCAL_MACHINE,
        OpenKeyEx,
        QueryValueEx,
        CloseKey,
        KEY_READ,
        EnumKey,
        WindowsError,
    )

    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        akey = OpenKeyEx(root, reg_path, 0, KEY_READ)
        for i in itertools.count():
            try:
                subname = EnumKey(akey, i)
            except WindowsError:
                break
            if subname.lower().find(fc_name.lower()) > 0:
                subkey = OpenKeyEx(akey, subname, 0, KEY_READ)
                pathname, regtype = QueryValueEx(subkey, "InstallLocation")
                CloseKey(subkey)
                return os.path.expandvars(pathname)
        # close key and root
        CloseKey(akey)
        CloseKey(root)
        return None
    except OSError:
        return None
def openurl(url):
    if platform == 'win32':
        # On Windows webbrowser.open calls os.startfile which calls ShellExecute which can't handle long arguments,
        # so discover and launch the browser directly.
        # https://blogs.msdn.microsoft.com/oldnewthing/20031210-00/?p=41553

        try:
            hkey = OpenKeyEx(HKEY_CURRENT_USER, r'Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice')
            (value, typ) = QueryValueEx(hkey, 'ProgId')
            CloseKey(hkey)
            if value in ['IE.HTTP', 'AppXq0fevzme2pys62n3e0fbqa7peapykr8v']:
                # IE and Edge can't handle long arguments so just use webbrowser.open and hope
                # https://blogs.msdn.microsoft.com/ieinternals/2014/08/13/url-length-limits/
                cls = None
            else:
                cls = value
        except:
            cls  = 'https'

        if cls:
            try:
                hkey = OpenKeyEx(HKEY_CLASSES_ROOT, r'%s\shell\open\command' % cls)
                (value, typ) = QueryValueEx(hkey, None)
                CloseKey(hkey)
                if 'iexplore' not in value.lower():
                    if '%1' in value:
                        subprocess.Popen(buf.value.replace('%1', url))
                    else:
                        subprocess.Popen('%s "%s"' % (buf.value, url))
                    return
            except:
                pass

    webbrowser.open(url)
Esempio n. 3
0
    def __read_manifest(self):
        repository_key = OpenKeyEx(HKEY_LOCAL_MACHINE,
                                   UPlay.REG_INSTALL_PATH + R"\Installs")

        games = []

        for sub_key_name in iter(RegKeyIter(repository_key)):
            try:
                sub_key = OpenKeyEx(repository_key, sub_key_name)
                details_key = OpenKeyEx(
                    HKEY_LOCAL_MACHINE,
                    UPlay.REG_DETAILS_PATH.format(appid=sub_key_name))

                games.append({
                    "appid":
                    sub_key_name,
                    "name":
                    QueryValueEx(details_key, "DisplayName")[0],
                    "game_path":
                    QueryValueEx(sub_key, "InstallDir")[0],
                    "icon_path":
                    QueryValueEx(details_key, "DisplayIcon")[0],
                })
            except Exception as e:
                self.__context.err("Failed to read game", sub_key_name, e)

        return games
    def __read_repository(self):
        root = ConnectRegistry(None, HKEY_CLASSES_ROOT)
        base_key = OpenKeyEx(root, WindowsStore.REPOSITORY_PATH)
        idx = 0
        games = []

        for sub_key_name in iter(RegKeyIter(base_key)):
            try:
                sub_key = OpenKeyEx(base_key, sub_key_name)
                idx += 1
                name = QueryValueEx(sub_key, "DisplayName")[0]
                if name.startswith("@{"):
                    # if it doesn't have a name we don't care for it
                    continue
                root_path = QueryValueEx(sub_key, "PackageRootFolder")[0]

                doc = minidom.parse(os.path.join(root_path,
                                                 "appxmanifest.xml"))

                apps = doc.getElementsByTagName("Application")
                if apps.length == 0:
                    continue
                app = apps[0]

                exeid = app.getAttribute("Id")
                exe_path = app.getAttribute("Executable")

                logo_path = None
                try:
                    visuals = app.getElementsByTagName("uap:VisualElements")[0]
                    logo_path = visuals.getAttribute("Square150x150Logo")
                except Exception as e:
                    self.__context.warn("failed to get logo", exeid, e)

                id_parts = sub_key_name.split("_")
                games.append({
                    "appid": id_parts[0],
                    "publisher": id_parts[-1],
                    "name": name,
                    "exeid": exeid,
                    "root_path": root_path,
                    "exe_path": exe_path,
                    "logo_path": logo_path
                })
            except Exception as e:
                # This may be an error but most likely it's simply not a "proper" application we
                # could start. May be a service or something
                self.__context.dbg("manifest not parsed", e)

        return games
Esempio n. 5
0
 def get_user_path() -> str:
     key = OpenKeyEx(HKEY_CURRENT_USER, 'Environment')
     try:
         path, _ = QueryValueEx(key, 'Path')
     finally:
         CloseKey(key)
     return path
Esempio n. 6
0
    def find_archive():
        reg_keys = [
            # Have confirmed sigthings of these keys:
            (HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", "InstallPath"),
            (HKEY_LOCAL_MACHINE, "Software\\Wow6432node\\Valve\\Steam",
             "InstallPath"),
            (HKEY_CURRENT_USER, "Software\\Valve\\Steam", "SteamPath"),

            # All the other possible combination, just to try everything:
            (HKEY_CURRENT_USER, "Software\\Wow6432node\\Valve\\Steam",
             "SteamPath"),
            (HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", "SteamPath"),
            (HKEY_LOCAL_MACHINE, "Software\\Wow6432node\\Valve\\Steam",
             "SteamPath"),
            (HKEY_CURRENT_USER, "Software\\Valve\\Steam", "InstallPath"),
            (HKEY_CURRENT_USER, "Software\\Wow6432node\\Valve\\Steam",
             "InstallPath"),
        ]

        for key, subkey, valkey in reg_keys:
            try:
                hkey = OpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE)
                try:
                    value, valtype = QueryValueEx(hkey, valkey)
                    if valtype == REG_SZ:
                        return pjoin(
                            value,
                            "steamapps\\common\\CookServeDelicious3\\data.win")
                finally:
                    CloseKey(hkey)
            except FileNotFoundError:
                pass

        raise FileNotFoundError('game archive not found')
Esempio n. 7
0
def win32_ver(release='', version='', csd='', ptype=''):
    try:
        from sys import getwindowsversion
    except ImportError:
        return release, version, csd, ptype
    try:
        from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
    except ImportError:
        from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
    winver = getwindowsversion()
    maj, min, build = winver.platform_version or winver[:3]
    version = '{0}.{1}.{2}'.format(maj, min, build)
    release = _WIN32_CLIENT_RELEASES.get(
        (maj, min)) or _WIN32_CLIENT_RELEASES.get((maj, None)) or release
    if winver[:2] == (maj, min):
        try:
            csd = 'SP{}'.format(winver.service_pack_major)
        except AttributeError:
            if csd[:13] == 'Service Pack ':
                csd = 'SP' + csd[13:]
    if getattr(winver, 'product_type', None) == 3:
        release = _WIN32_SERVER_RELEASES.get(
            (maj, min)) or _WIN32_SERVER_RELEASES.get((maj, None)) or release
    key = None
    try:
        key = OpenKeyEx(HKEY_LOCAL_MACHINE,
                        'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
        ptype = QueryValueEx(key, 'CurrentType')[0]
    except:
        pass
    finally:
        if key:
            CloseKey(key)
    return release, version, csd, ptype
Esempio n. 8
0
 def get_system_path() -> str:
     key = OpenKeyEx(HKEY_LOCAL_MACHINE, r'System\CurrentControlSet\Control\Session Manager\Environment')
     try:
         path, _ = QueryValueEx(key, 'Path')
     finally:
         CloseKey(key)
     return path
Esempio n. 9
0
def _test_key_present_view(root: int, path: str, key: str, view: int) -> bool:
    try:
        with OpenKeyEx(root, f'{path}\\{key}', 0, KEY_READ | view):
            return True
    except OSError as e:
        if e.winerror == 2:
            return False
        else:
            raise
Esempio n. 10
0
 def __find_store(self):
     try:
         root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
         base_key = OpenKeyEx(root, EGS.LAUNCHER_PATH)
         data_path = QueryValueEx(base_key, "AppDataPath")
         self.__valid = True
         return data_path[0]
     except Exception as e:
         self.__context.warn(
             "Failed to find path, maybe it isn't installed", e)
Esempio n. 11
0
def disablebUpdater():
    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        bUpdater_key = OpenKeyEx(
            root, r"SOFTWARE\Policies\Adobe\Adobe Acrobat\DC\FeatureLockDown")
        SetValueEx(bUpdater_key, "bUpdater", 0, REG_DWORD, 0)
    except OSError:
        bUpdater_key = CreateKey(
            root, r"SOFTWARE\Policies\Adobe\Adobe Acrobat\DC\FeatureLockDown")
        SetValueEx(bUpdater_key, "bUpdater", 0, REG_DWORD, 0)
Esempio n. 12
0
 def __get_install_path(self):
     try:
         root = ConnectRegistry(None, HKEY_CURRENT_USER)
         steam_key = OpenKeyEx(root, Steam.PATH)
         res_exe = QueryValueEx(steam_key, "SteamExe")
         res_path = QueryValueEx(steam_key, "SteamPath")
         self.__valid = True
         return res_exe[0], os.path.normpath(res_path[0])
     except Exception as e:
         self.__context.warn("Failed to find path, maybe isn't installed",
                             e)
Esempio n. 13
0
def sys_bgcolor(pyplot):
    """Reads system preference and sets plt background accordingly"""
    from winreg import ConnectRegistry, HKEY_CURRENT_USER, OpenKeyEx, QueryValueEx
    root = ConnectRegistry(None, HKEY_CURRENT_USER)
    policy_key = OpenKeyEx(
        root, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize")
    light, _ = QueryValueEx(policy_key, "AppsUseLightTheme")
    if light:
        pyplot.style.use('default')
    else:
        pyplot.style.use('dark_background')
Esempio n. 14
0
 def __get_exe_path(self):
     try:
         root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
         base_key = OpenKeyEx(root, EGS.ICON_PATH)
         data_path = QueryValueEx(base_key, "")
         self.__context.dbg("data path", data_path)
         self.__valid = True
         return data_path[0].split(",")[0]
     except Exception as e:
         self.__context.warn(
             "Failed to find executable, maybe it isn't installed", e)
Esempio n. 15
0
def windows_group_policy_path():
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ
    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome")
        user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir")
        if type_ == REG_EXPAND_SZ:
            user_data_dir = os.path.expandvars(user_data_dir)
        elif type_ != REG_SZ:
            return None
    except OSError:
        return None
    return os.path.join(user_data_dir, "Default", "Cookies")
Esempio n. 16
0
 def test_named_arguments(self):
     from winreg import KEY_ALL_ACCESS, CreateKeyEx, DeleteKey, OpenKeyEx
     with CreateKeyEx(key=self.root_key,
                      sub_key=self.test_key_name,
                      reserved=0,
                      access=KEY_ALL_ACCESS) as ckey:
         assert ckey.handle != 0
     with OpenKeyEx(key=self.root_key,
                    sub_key=self.test_key_name,
                    reserved=0,
                    access=KEY_ALL_ACCESS) as okey:
         assert okey.handle != 0
     DeleteKey(self.root_key, self.test_key_name)
Esempio n. 17
0
def get_sof2_path():
    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        policy_key = OpenKeyEx(
            root,
            r"SOFTWARE\WOW6432Node\Activision\Soldier of Fortune II - Double Helix"
        )
        result, _type = QueryValueEx(policy_key, "InstallPath")
        buffer = ctypes.create_unicode_buffer(BUFFER_SIZE)
        GetLongPathNameW(result, buffer, BUFFER_SIZE)
        return buffer.value
    except OSError:
        return None
Esempio n. 18
0
def toggle_color_mode():
    """Toggles system color scheme preference."""
    from winreg import ConnectRegistry, HKEY_CURRENT_USER, REG_SZ, KEY_ALL_ACCESS, OpenKeyEx, QueryValueEx, SetValueEx, CloseKey
    root = ConnectRegistry(None, HKEY_CURRENT_USER)
    policy_key = OpenKeyEx(
        root,
        r"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize",
        access=KEY_ALL_ACCESS)
    light, _ = QueryValueEx(policy_key, "AppsUseLightTheme")
    SetValueEx(policy_key, "AppsUseLightTheme", 0, REG_SZ, str(1 - int(light)))
    SetValueEx(policy_key, "SystemUsesLightTheme", 0, REG_SZ,
               str(1 - int(light)))
    CloseKey(policy_key)
Esempio n. 19
0
    def __read_manifest(self):
        repository_key = OpenKeyEx(HKEY_LOCAL_MACHINE, GOG.GAMES_PATH)

        games = []

        for sub_key_name in iter(RegKeyIter(repository_key)):
            try:
                sub_key = OpenKeyEx(repository_key, sub_key_name)

                exe = QueryValueEx(sub_key, "EXE")[0]
                if os.path.exists(exe):
                    games.append({
                        "appid": QueryValueEx(sub_key, "gameID")[0],
                        "name": QueryValueEx(sub_key, "startMenu")[0],
                        "game_path": QueryValueEx(sub_key, "path")[0],
                        "exe_path": exe,
                    })
                else:
                    self.__context.warn("not found", exe)
            except Exception as e:
                self.__context.warn("Failed to read game info", e)

        return games
Esempio n. 20
0
def windows_group_policy_path():
    # we know that we're running under windows at this point so it's safe to do these imports
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ
    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome")
        user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir")
        if type_ == REG_EXPAND_SZ:
            user_data_dir = os.path.expandvars(user_data_dir)
        elif type_ != REG_SZ:
            return None
    except OSError:
        return None
    return chrome_active_cookie_file(user_data_dir)
Esempio n. 21
0
 def _c(*args):
     res = None
     key_id = id(args[0]) if len(args) == 2 else None
     try:
         with OpenKeyEx(*args) as c:
             res = id(c)
             yield c
     except Exception as exception:
         res = exception
         raise exception
     finally:
         if len(args) == 4:
             hive_open[args] = res
         elif len(args) == 2:
             key_open[key_id][args[1]] = res
Esempio n. 22
0
def win32_ver(release='', version='', csd='', ptype=''):
    try:
        from sys import getwindowsversion
    except ImportError:
        return release, version, csd, ptype
    try:
        from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
    except ImportError:
        from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE

    winver = getwindowsversion()
    maj, min, build = winver.platform_version or winver[:3]
    version = '{0}.{1}.{2}'.format(maj, min, build)

    release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
               _WIN32_CLIENT_RELEASES.get((maj, None)) or
               release)

    # getwindowsversion() reflect the compatibility mode Python is
    # running under, and so the service pack value is only going to be
    # valid if the versions match.
    if winver[:2] == (maj, min):
        try:
            csd = 'SP{}'.format(winver.service_pack_major)
        except AttributeError:
            if csd[:13] == 'Service Pack ':
                csd = 'SP' + csd[13:]

    # VER_NT_SERVER = 3
    if getattr(winver, 'product_type', None) == 3:
        release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
                   _WIN32_SERVER_RELEASES.get((maj, None)) or
                   release)

    key = None
    try:
        key = OpenKeyEx(HKEY_LOCAL_MACHINE,
                        r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
        ptype = QueryValueEx(key, 'CurrentType')[0]
    except:
        pass
    finally:
        if key:
            CloseKey(key)

    return release, version, csd, ptype
def get_steam_install_path():
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx
    root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
    steam_software_key = OpenKeyEx(root, r"SOFTWARE\Wow6432Node\Valve\Steam")
    install_path, type_ = QueryValueEx(steam_software_key, "InstallPath")
    return install_path
Esempio n. 24
0
 def __get_install_path(self):
     paths_key = OpenKeyEx(HKEY_LOCAL_MACHINE, UPlay.REG_INSTALL_PATH)
     return QueryValueEx(paths_key, "InstallDir")[0]
Esempio n. 25
0
    # running under, and so the service pack value is only going to be
    # valid if the versions match.
    if winver[:2] == (maj, min):
        try:
            csd = 'SP{}'.format(winver.service_pack_major)
        except AttributeError:
            if csd[:13] == 'Service Pack ':
                csd = 'SP' + csd[13:]
    # VER_NT_SERVER = 3
    if getattr(winver, 'product_type', None) == 3:
        release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
                   _WIN32_SERVER_RELEASES.get((maj, None)) or
                   release)
    key = None
    try:
        key = OpenKeyEx(HKEY_LOCAL_MACHINE,
                        r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
        ptype = QueryValueEx(key, 'CurrentType')[0]
    except:
        pass
    finally:
        if key:
            CloseKey(key)
    return release, version, csd, ptype
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None
    try:
        import plistlib
    except ImportError:
        return None
Esempio n. 26
0
bits = platform.architecture()[0][0:2]

incDirs = []
libDirs = []
libs = ['mimerapi']

if plat == 'Linux':
    pass
elif plat == 'Darwin':
    incDirs = ['/usr/local/include']
    libDirs = ['/usr/local/lib']
elif plat == 'Windows':
    libs = ['mimapi' + bits]
    from winreg import HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY, ConnectRegistry, OpenKeyEx, QueryValueEx, CloseKey, EnumKey, OpenKeyEx
    root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
    mimer_key = OpenKeyEx(root, r"SOFTWARE\Mimer\Mimer SQL", 0,  KEY_READ | KEY_WOW64_64KEY)
    index = 0
    while True:
        try:
            key = EnumKey(mimer_key,index)
            if key != "License" and key != "SQLHosts":
                version = key
                break
            index = index + 1
        except OSError:
            break
    inner_key = OpenKeyEx(mimer_key, version)
    path = QueryValueEx(inner_key, 'PathName')[0]
    CloseKey(inner_key)
    CloseKey(root)
    if bits == '64':
Esempio n. 27
0
 def set_user_path(path: str) -> None:
     key = OpenKeyEx(HKEY_CURRENT_USER, 'Environment', access=KEY_SET_VALUE)
     try:
         SetValueEx(key, 'Path', 0, REG_EXPAND_SZ, path)
     finally:
         CloseKey(key)
Esempio n. 28
0
 def __get_exe_path(self):
     paths_key = OpenKeyEx(HKEY_LOCAL_MACHINE, GOG.CLIENT_PATH)
     client_path = QueryValueEx(paths_key, "client")[0]
     return os.path.join(client_path, GOG.CLIENT_EXE)