当前位置: 首页>>代码示例>>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属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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"):
        userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with _winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = _winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            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:aliyun,项目名称:oss-ftp,代码行数:26,代码来源:win_add2path.py

示例2: 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

示例3: get_str_type

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import REG_EXPAND_SZ [as 别名]
def get_str_type(reg_type):
    if reg_type == _winreg.REG_BINARY:
        return "REG_BINARY"
    elif reg_type == _winreg.REG_DWORD:
        return "REG_DWORD"
    elif reg_type == _winreg.REG_DWORD_BIG_ENDIAN:
        return "REG_DWORD_BIG_ENDIAN"
    elif reg_type == _winreg.REG_DWORD_LITTLE_ENDIAN:
        return "REG_DWORD_LITTLE_ENDIAN"
    elif reg_type == _winreg.REG_EXPAND_SZ:
        return "REG_EXPAND_SZ"
    elif reg_type == _winreg.REG_LINK:
        return "REG_LINK"
    elif reg_type == _winreg.REG_MULTI_SZ:
        return "REG_MULTI_SZ"
    elif reg_type == _winreg.REG_SZ:
        return "REG_SZ" 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:19,代码来源:registry_obj.py

示例4: get_data

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import REG_EXPAND_SZ [as 别名]
def get_data(self):
        reg_type = self.value.get_type()
        if reg_type == _winreg.REG_DWORD:
            return self.value.get_data_as_integer()
        elif reg_type == _winreg.REG_DWORD_LITTLE_ENDIAN:
            return self.value.get_data_as_integer()
        elif reg_type == _winreg.REG_DWORD_BIG_ENDIAN:
            return self.value.get_data_as_integer()
        elif reg_type == _winreg.REG_SZ:
            return self.value.get_data_as_string()
        elif reg_type == _winreg.REG_EXPAND_SZ:
            return self.value.get_data_as_string()
        elif reg_type == _winreg.REG_LINK:
            return self.value.get_data_as_string()

        return self.value.get_data() 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:18,代码来源:registry_obj.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: 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

示例7: 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

示例8: is_ran_on_startup

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import REG_EXPAND_SZ [as 别名]
def is_ran_on_startup(program_name):
	"""
	Returns True if specified program is set to be ran on startup, either
	by XDG autostart or by windows registry.
	Only name (desktop filename or registry key) is checked.
	"""
	if IS_WINDOWS:
		# Check if there is value for application in ...\Run
		try:
			key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
			trash, keytype = _winreg.QueryValueEx(key, program_name)
			_winreg.CloseKey(key)
			return keytype in (_winreg.REG_SZ, _winreg.REG_EXPAND_SZ, _winreg.REG_MULTI_SZ)
		except WindowsError:
			# Key not found
			return False
	else:
		# Check if there application.desktop file exists
		desktopfile = os.path.join(get_config_dir(), "autostart", "%s.desktop" % (program_name,))
		if not os.path.exists(desktopfile):
			return False
		# Check if desktop file is not marked as hidden
		# (stupid way, but should work)
		is_entry = False
		with open(desktopfile, "r") as f:
			for line in f.readlines():
				line = line.strip(" \r\t\n").lower()
				if line == "[desktop entry]":
					is_entry = True
					continue
				if "=" in line:
					key, value = line.split("=", 1)
					if key.strip(" ") == "hidden":
						if value.strip(" ") == "true":
							# Desktop file is 'hidden', i.e. disabled
							return False
		# File is present and not hidden - autostart is enabled
		return is_entry 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:40,代码来源:tools.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: interpret

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import REG_EXPAND_SZ [as 别名]
def interpret(value_type, value):
    if value_type == _winreg.REG_SZ:
        return value
    elif value_type == _winreg.REG_EXPAND_SZ:
        return os.path.expandvars(value)
    else:
        return None 
开发者ID:ActiveState,项目名称:code,代码行数:9,代码来源:recipe-577381.py

示例11: printReg

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import REG_EXPAND_SZ [as 别名]
def printReg(hive, value, type, fullkey, outFile, objRegistry, key=None):
	if not key:
		key = fullkey
		
	if type == _winreg.REG_SZ:
		result,reg_value = objRegistry.GetStringValue(hDefKey=hive,sSubKeyName=fullkey,sValueName=value)
	elif type == _winreg.REG_EXPAND_SZ:
		result,reg_value = objRegistry.GetExpandedStringValue(hDefKey=hive,sSubKeyName=fullkey,sValueName=value)
	elif type == _winreg.REG_BINARY:
		result,reg_value = objRegistry.GetBinaryValue(hDefKey=hive,sSubKeyName=fullkey,sValueName=value)
		r_value = ""
		if result == 0:
			for decimal in reg_value:
				r_value += "%0.2X" % decimal
		reg_value = "[BINARY DATA] " + r_value
	elif type == _winreg.REG_DWORD:
		result,reg_value = objRegistry.GetDWORDValue(hDefKey=hive,sSubKeyName=fullkey,sValueName=value)
	elif type == _winreg.REG_MULTI_SZ:
		result,reg_value = objRegistry.GetMultiStringValue(hDefKey=hive,sSubKeyName=fullkey,sValueName=value)
	else:
		reg_value = "OTHER_TYPE"
	
	if reg_value == None:
		reg_value = "NULL"
	
	reg_value = convert_to_string(reg_value)
	outFile.write(key.replace(","," ") + "," + value.replace(","," ") + "," + reg_value.replace(","," ") + "\n")

#convert windows datetime to nicely formatted date 
开发者ID:CIS-CERT,项目名称:CIS-ESP,代码行数:31,代码来源:support.py


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