当前位置: 首页>>代码示例>>Python>>正文


Python winreg.REG_EXPAND_SZ属性代码示例

本文整理汇总了Python中winreg.REG_EXPAND_SZ属性的典型用法代码示例。如果您正苦于以下问题:Python winreg.REG_EXPAND_SZ属性的具体用法?Python winreg.REG_EXPAND_SZ怎么用?Python winreg.REG_EXPAND_SZ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在winreg的用法示例。


在下文中一共展示了winreg.REG_EXPAND_SZ属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_windows_path_var

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def set_windows_path_var(self, value):
        import ctypes

        with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
            with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
                winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, value)

        # Tell other processes to update their environment
        HWND_BROADCAST = 0xFFFF
        WM_SETTINGCHANGE = 0x1A

        SMTO_ABORTIFHUNG = 0x0002

        result = ctypes.c_long()
        SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
        SendMessageTimeoutW(
            HWND_BROADCAST,
            WM_SETTINGCHANGE,
            0,
            u"Environment",
            SMTO_ABORTIFHUNG,
            5000,
            ctypes.byref(result),
        ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:26,代码来源:get-poetry.py

示例2: windows_group_policy_path

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
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 os.path.join(user_data_dir, "Default", "Cookies")


# Code adapted slightly from https://github.com/Arnie97/chrome-cookies 
开发者ID:borisbabic,项目名称:browser_cookie3,代码行数:19,代码来源:__init__.py

示例3: modify

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
        userpath = os.path.dirname(usersite)
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = winreg.QueryValueEx(key, PATH)[0]
        except OSError:
            envpath = DEFAULT

        paths = [envpath]
        for path in (pythonpath, scripts, userscripts):
            if path and path not in envpath and os.path.isdir(path):
                paths.append(path)

        envpath = os.pathsep.join(paths)
        winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath 
开发者ID:holzschu,项目名称:python3_ios,代码行数:27,代码来源:win_add2path.py

示例4: path_cleanup

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def path_cleanup():
    ''' Removes SIMNIBS from PATH '''
    if sys.platform in ['linux', 'darwin']:
        bashrc, backup_file = _get_bashrc()

        if not os.path.isfile(bashrc):
            print('Could not find bashrc file')
            return

        print('Removing SimNIBS install from PATH')
        print(f'Backing up the bashrc file at {backup_file}')
        _copy_and_log(bashrc, backup_file)
        with open(backup_file, 'r') as fin:
            with open(bashrc, 'w') as fout:
                for line in fin:
                    if not re.search('simnibs', line, re.IGNORECASE):
                        fout.write(line)
    else:
        simnibs_env_vars = _get_win_simnibs_env_vars()
        path = _get_win_path()
        path = path.split(';')
        path = [p for p in path if len(p) > 0]
        for key, value in simnibs_env_vars.items():
            # If the directory is in the PATH variable, remove it
            path = [
                os.path.normpath(p) for p in path if not (
                os.path.normpath(value) in os.path.normpath(p))]
            # Remove environment variable
            with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
                winreg.DeleteValue(reg, key)

        # write out the PATH with SimNIBS removed
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
            path = ';'.join(path) + ';'
            winreg.SetValueEx(reg,'Path', 0, winreg.REG_EXPAND_SZ, path) 
开发者ID:simnibs,项目名称:simnibs,代码行数:37,代码来源:postinstall_simnibs.py

示例5: set_envvar_in_registry

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def set_envvar_in_registry(envvar, value):
    try:
        import winreg
    except ImportError:
        import _winreg as winreg

    reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    with winreg.OpenKey(reg, KEY, 0, winreg.KEY_ALL_ACCESS) as regkey:
        winreg.SetValueEx(regkey, envvar, 0, winreg.REG_EXPAND_SZ, value) 
开发者ID:coala,项目名称:coala-quickstart,代码行数:11,代码来源:store_env_in_registry.py

示例6: Reg2Py

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def Reg2Py(data, size, data_type):
    if data_type == winreg.REG_DWORD:
        if size == 0:
            return 0
        return ctypes.cast(data, ctypes.POINTER(ctypes.c_int)).contents.value
    elif data_type == winreg.REG_SZ or data_type == winreg.REG_EXPAND_SZ:
        return ctypes.wstring_at(data, size // 2).rstrip(u"\x00")
    elif data_type == winreg.REG_MULTI_SZ:
        return ctypes.wstring_at(data, size // 2).rstrip(u"\x00").split(u"\x00")
    else:
        if size == 0:
            return None
        return ctypes.string_at(data, size) 
开发者ID:google,项目名称:rekall,代码行数:15,代码来源:registry.py

示例7: install

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def install():
    if check_installed() is False:
        runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
            r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
            winreg.KEY_WRITE)
        winreg.SetValueEx(runkey, "Px", 0, winreg.REG_EXPAND_SZ,
            get_script_cmd())
        winreg.CloseKey(runkey)
        pprint("Px installed successfully")
    else:
        pprint("Px already installed")

    sys.exit() 
开发者ID:genotrance,项目名称:px,代码行数:15,代码来源:px.py

示例8: get_value_from_tuple

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def get_value_from_tuple(value, value_type):
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    if value_type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ):
        if "\0" in value:
            return value[: value.index("\0")]
        return value
    return None 
开发者ID:pypa,项目名称:pipenv,代码行数:12,代码来源:_winconsole.py

示例9: setenv

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def setenv(self, name, value):
        # Note: for 'system' scope, you must run this as Administrator
        key = winreg.OpenKey(self.root, self.subkey, 0, winreg.KEY_ALL_ACCESS)
        winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
        winreg.CloseKey(key)
        # For some strange reason, calling SendMessage from the current process
        # doesn't propagate environment changes at all.
        # TODO: handle CalledProcessError (for assert)
        check_call('''\
"%s" -c "import win32api, win32con; assert win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')"''' % sys.executable) 
开发者ID:ActiveState,项目名称:code,代码行数:12,代码来源:recipe-577621.py

示例10: path_setup

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import REG_EXPAND_SZ [as 别名]
def path_setup(scripts_dir, force=False, silent=False):
    ''' Modifies the bash startup path and postpends SimNIBS to the PATH '''
    scripts_dir = os.path.abspath(scripts_dir)
    silent = silent and GUI
    if sys.platform in ['linux', 'darwin']:
        bashrc, _ = _get_bashrc()
        if os.path.exists(bashrc):
            has_simnibs = (
                re.search('simnibs', open(bashrc, 'r').read(), re.IGNORECASE)
                is not None)
        else:
            has_simnibs = False

    if sys.platform == 'win32':
        simnibs_env_vars = _get_win_simnibs_env_vars()
        has_simnibs = len(simnibs_env_vars) != 0

    if has_simnibs:
        if force:
             overwrite=True
        else:
            overwrite = _get_input(
                'Found another SimNIBS install, overwite it from the PATH?',
                silent)

        if not overwrite:
            print('Not Adding the current SimNIBS install to the PATH')
            return

        path_cleanup()

    print(f'Postpending {scripts_dir} to the PATH')
    if sys.platform in ['linux', 'darwin']:
        with open(bashrc, 'a') as f:
            f.write('\n')
            f.write('## Added by SimNIBS\n')
            f.write(f'SIMNIBS_BIN="{scripts_dir}"\n')
            f.write('export PATH=${PATH}:${SIMNIBS_BIN}')

    else:
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
            winreg.SetValueEx(reg,'SIMNIBS_BIN', 0, winreg.REG_SZ, scripts_dir)
            path = scripts_dir + ';' + _get_win_path()
            winreg.SetValueEx(reg,'Path', 0, winreg.REG_EXPAND_SZ, path) 
开发者ID:simnibs,项目名称:simnibs,代码行数:46,代码来源:postinstall_simnibs.py


注:本文中的winreg.REG_EXPAND_SZ属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。