當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。