本文整理匯總了Python中winreg.OpenKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.OpenKey方法的具體用法?Python winreg.OpenKey怎麽用?Python winreg.OpenKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.OpenKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: is_using_dcs_steam_edition
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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
示例2: is_using_dcs_standalone_edition
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def is_using_dcs_standalone_edition():
"""
Check if DCS World standalone edition is installed on this computer
:return True if Standalone is installed, False if it is not
"""
if not is_windows_os:
return False
try:
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
winreg.CloseKey(dcs_path_key)
return True
except FileNotFoundError as fnfe:
try:
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World OpenBeta")
winreg.CloseKey(dcs_path_key)
return True
except FileNotFoundError:
return False
示例3: _get_win_folder_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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
示例4: set_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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),
)
示例5: _find_chrome_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def _find_chrome_win():
import winreg as reg
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE:
try:
reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ)
chrome_path = reg.QueryValue(reg_key, None)
reg_key.Close()
if not os.path.isfile(chrome_path):
continue
except WindowsError:
chrome_path = None
else:
break
return chrome_path
示例6: default_cm3d2_dir
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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 OpenKey [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 OpenKey [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 OpenKey [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_simnibs_env_vars
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def _get_win_simnibs_env_vars():
''' 'Creates a disctionary with environment names and values '''
simnibs_env_vars = {}
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment') as reg:
_, num_values, _ = winreg.QueryInfoKey(reg)
for i in range(num_values):
var_name, value, _ = winreg.EnumValue(reg, i)
if 'SIMNIBS' in var_name:
simnibs_env_vars[var_name] = value
return simnibs_env_vars
示例11: _get_win_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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
示例12: path_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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)
示例13: uninstaller_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def uninstaller_cleanup():
if sys.platform == 'win32':
try:
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
access=winreg.KEY_WRITE) as reg:
winreg.DeleteKey(reg, 'SimNIBS')
except FileNotFoundError:
pass
示例14: set_envvar_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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)
示例15: proxy_bypass_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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