本文整理匯總了Python中winreg.HKEY_CURRENT_USER屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.HKEY_CURRENT_USER屬性的具體用法?Python winreg.HKEY_CURRENT_USER怎麽用?Python winreg.HKEY_CURRENT_USER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.HKEY_CURRENT_USER屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_win_folder_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [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
示例2: set_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [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),
)
示例3: _find_chrome_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [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
示例4: get_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [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
示例5: _delete_key_if_empty
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [as 別名]
def _delete_key_if_empty(self, service):
key_name = self._key_for_service(service)
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS
)
try:
winreg.EnumValue(key, 0)
return
except WindowsError:
pass
winreg.CloseKey(key)
# it's empty; delete everything
while key_name != 'Software':
parent, sep, base = key_name.rpartition('\\')
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, parent, 0, winreg.KEY_ALL_ACCESS
)
winreg.DeleteKey(key, base)
winreg.CloseKey(key)
key_name = parent
示例6: _get_launcher_install_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [as 別名]
def _get_launcher_install_path(self) -> Optional[str]:
if is_windows():
try:
for h_root in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE):
with winreg.OpenKey(h_root, r"Software\Microsoft\Windows\CurrentVersion\Uninstall") as h_apps:
for idx in range(winreg.QueryInfoKey(h_apps)[0]):
try:
with winreg.OpenKeyEx(h_apps, winreg.EnumKey(h_apps, idx)) as h_app_info:
def get_value(key):
return winreg.QueryValueEx(h_app_info, key)[0]
if get_value("DisplayName") == self._LAUNCHER_DISPLAY_NAME:
installer_path = get_value("InstallLocation")
if os.path.exists(str(installer_path)):
return installer_path
except (WindowsError, KeyError, ValueError):
continue
except (WindowsError, KeyError, ValueError):
logging.exception("Failed to get client install location")
return None
else:
return None
示例7: test_reg_class
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_CURRENT_USER [as 別名]
def test_reg_class(self):
from distutils.msvc9compiler import Reg
self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
# looking for values that should exist on all
# windows registeries versions.
path = r'Control Panel\Desktop'
v = Reg.get_value(path, 'dragfullwindows')
self.assertIn(v, ('0', '1', '2'))
import winreg
HKCU = winreg.HKEY_CURRENT_USER
keys = Reg.read_keys(HKCU, 'xxxx')
self.assertEqual(keys, None)
keys = Reg.read_keys(HKCU, r'Control Panel')
self.assertIn('Desktop', keys)