Python winreg 模块,REG_EXPAND_SZ 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用winreg.REG_EXPAND_SZ

项目:pyVirtualize    作者:rocky1109    | 项目源码 | 文件源码
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)
项目:constructor    作者:conda    | 项目源码 | 文件源码
def sz_expand(value, value_type):
    if value_type == reg.REG_EXPAND_SZ:
        return reg.ExpandEnvironmentStrings(value)
    else:
        return value
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def setEnvironment(scope, name, value):
    assert scope in ('user', 'system')
    #INFO_MSG('set environment: name=%s, value=%s' % (name, value))

    if platform.system() == 'Windows':
        root, subkey = getWindowsEnvironmentKey(scope)
        # Note: for 'system' scope, you must run this as Administrator
        key = winreg.OpenKey(root, subkey, 0, winreg.KEY_ALL_ACCESS)
        winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
        winreg.CloseKey(key)
    else:
        if name.lower() == 'uid':
            uid, username = value
            if uid != str(os.geteuid()):
                ret, cret = syscommand('bash -c \'usermod -d /home/%s/ -u %s %s\'' % (pwd.getpwnam(username).pw_dir, uid, username), True)
                INFO_MSG(ret)
                INFO_MSG(cret)
            return

        userhome = "~"
        if len(os_user_name) > 0:
            userhome = pwd.getpwnam(os_user_name).pw_dir 

        f = open('%s/.bashrc' % userhome, 'a')
        f.write("export %s=%s\n\n" % (name, value))
        f.close()

        if os.geteuid() > 0:
            syscommand('bash -c \'source %s/.bashrc\'' % userhome, False)