本文整理匯總了Python中winreg.QueryValueEx方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.QueryValueEx方法的具體用法?Python winreg.QueryValueEx怎麽用?Python winreg.QueryValueEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.QueryValueEx方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _win32_getvalue
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def _win32_getvalue(key,name,default=''):
""" Read a value for name from the registry key.
In case this fails, default is returned.
"""
try:
# Use win32api if available
from win32api import RegQueryValueEx
except ImportError:
# On Python 2.0 and later, emulate using winreg
import winreg
RegQueryValueEx = winreg.QueryValueEx
try:
return RegQueryValueEx(key,name)
except:
return default
示例2: _get_windows_python_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def _get_windows_python_path(x64):
"""Get the path to Python.exe on Windows."""
parts = str(sys.version_info.major), str(sys.version_info.minor)
ver = ''.join(parts)
dot_ver = '.'.join(parts)
if x64:
path = (r'SOFTWARE\Python\PythonCore\{}\InstallPath'
.format(dot_ver))
fallback = r'C:\Python{}\python.exe'.format(ver)
else:
path = (r'SOFTWARE\WOW6432Node\Python\PythonCore\{}-32\InstallPath'
.format(dot_ver))
fallback = r'C:\Python{}-32\python.exe'.format(ver)
try:
key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, path)
return winreg.QueryValueEx(key, 'ExecutablePath')[0]
except FileNotFoundError:
return fallback
示例3: is_using_dcs_steam_edition
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def is_using_dcs_steam_edition():
"""
Check if DCS World : Steam Edition version is installed on this computer
:return True if DCS Steam edition is installed,
-1 if DCS Steam Edition is registered in Steam apps but not installed,
False if never installed in Steam
"""
if not is_windows_os:
return False
try:
# Note : Steam App ID for DCS World is 223750
dcs_steam_app_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam\\Apps\\223750")
installed = winreg.QueryValueEx(dcs_steam_app_key, "Installed")
winreg.CloseKey(dcs_steam_app_key)
if installed[0] == 1:
return True
else:
return False
except FileNotFoundError as fnfe:
return False
示例4: _get_win_folder_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def _get_win_folder_from_registry(csidl_name):
"""This is a fallback technique at best. I'm not sure if using the
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
if PY3:
import winreg as _winreg
else:
import _winreg
shell_folder_name = {
"CSIDL_APPDATA": "AppData",
"CSIDL_COMMON_APPDATA": "Common AppData",
"CSIDL_LOCAL_APPDATA": "Local AppData",
}[csidl_name]
key = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
dir, type = _winreg.QueryValueEx(key, shell_folder_name)
return dir
示例5: windows_group_policy_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [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
示例6: default_cm3d2_dir
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def default_cm3d2_dir(base_dir, file_name, new_ext):
if not base_dir:
if preferences().cm3d2_path:
base_dir = os.path.join(preferences().cm3d2_path, "GameData", "*." + new_ext)
else:
try:
import winreg
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\KISS\カスタムメイド3D2') as key:
base_dir = winreg.QueryValueEx(key, 'InstallPath')[0]
preferences().cm3d2_path = base_dir
base_dir = os.path.join(base_dir, "GameData", "*." + new_ext)
except: pass
if file_name:
base_dir = os.path.join(os.path.split(base_dir)[0], file_name)
base_dir = os.path.splitext(base_dir)[0] + "." + new_ext
return base_dir
# 一時ファイル書き込みと自動バックアップを行うファイルオブジェクトを返す
示例7: get_home_dir
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def get_home_dir(self, username):
"""Return the user's profile directory, the closest thing
to a user home directory we have on Windows.
"""
try:
sid = win32security.ConvertSidToStringSid(
win32security.LookupAccountName(None, username)[0])
except pywintypes.error as err:
raise AuthorizerError(err)
path = r"SOFTWARE\Microsoft\Windows NT" \
r"\CurrentVersion\ProfileList" + "\\" + sid
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
except WindowsError:
raise AuthorizerError(
"No profile directory defined for user %s" % username)
value = winreg.QueryValueEx(key, "ProfileImagePath")[0]
home = win32api.ExpandEnvironmentStrings(value)
if not PY3 and not isinstance(home, unicode):
home = home.decode('utf8')
return home
示例8: get_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def get_password(self, service, username):
"""Get password of the username for the service
"""
try:
# fetch the password
key = self._key_for_service(service)
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
password_saved = winreg.QueryValueEx(hkey, username)[0]
password_base64 = password_saved.encode('ascii')
# decode with base64
password_encrypted = base64.decodestring(password_base64)
# decrypted the password
password = _win_crypto.decrypt(password_encrypted).decode('utf-8')
except EnvironmentError:
password = None
return password
示例9: proxy_bypass_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def proxy_bypass_registry(host):
try:
if is_py3:
import winreg
else:
import _winreg as winreg
except ImportError:
return False
try:
internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
# ProxyEnable could be REG_SZ or REG_DWORD, normalizing it
proxyEnable = int(winreg.QueryValueEx(internetSettings,
'ProxyEnable')[0])
# ProxyOverride is almost always a string
proxyOverride = winreg.QueryValueEx(internetSettings,
'ProxyOverride')[0]
except OSError:
return False
if not proxyEnable or not proxyOverride:
return False
# make a check value list from the registry entry: replace the
# '<local>' string by the localhost entry and the corresponding
# canonical entry.
proxyOverride = proxyOverride.split(';')
# now check if we match one of the registry values.
for test in proxyOverride:
if test == '<local>':
if '.' not in host:
return True
test = test.replace(".", r"\.") # mask dots
test = test.replace("*", r".*") # change glob sequence
test = test.replace("?", r".") # change glob char
if re.match(test, host, re.I):
return True
return False
示例10: _get_win_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def _get_win_path():
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment') as reg:
try:
path = winreg.QueryValueEx(reg, 'Path')[0]
except FileNotFoundError: # PATH not set
path = ''
return path
示例11: proxy_bypass_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryValueEx [as 別名]
def proxy_bypass_registry(host):
if is_py3:
import winreg
else:
import _winreg as winreg
try:
internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
proxyEnable = winreg.QueryValueEx(internetSettings,
'ProxyEnable')[0]
proxyOverride = winreg.QueryValueEx(internetSettings,
'ProxyOverride')[0]
except OSError:
return False
if not proxyEnable or not proxyOverride:
return False
# make a check value list from the registry entry: replace the
# '<local>' string by the localhost entry and the corresponding
# canonical entry.
proxyOverride = proxyOverride.split(';')
# now check if we match one of the registry values.
for test in proxyOverride:
if test == '<local>':
if '.' not in host:
return True
test = test.replace(".", r"\.") # mask dots
test = test.replace("*", r".*") # change glob sequence
test = test.replace("?", r".") # change glob char
if re.match(test, host, re.I):
return True
return False