本文整理匯總了Python中winreg.KEY_ALL_ACCESS屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.KEY_ALL_ACCESS屬性的具體用法?Python winreg.KEY_ALL_ACCESS怎麽用?Python winreg.KEY_ALL_ACCESS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.KEY_ALL_ACCESS屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [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),
)
示例2: _delete_key_if_empty
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [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
示例3: __init__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def __init__(self, args):
self.listen = None
for option in args.listen:
protos = [x.name for x in option.protos]
if option.unix or 'ssl' in protos or 'secure' in protos:
continue
if 'http' in protos:
self.listen = option
break
if self.listen is None:
print('No server listen on localhost by http')
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.KEY, 0, winreg.KEY_ALL_ACCESS)
value, regtype = winreg.QueryValueEx(key, self.SUBKEY)
assert regtype == winreg.REG_BINARY
server = f'localhost:{self.listen.port}'.encode()
bypass = '<local>'.encode()
counter = int.from_bytes(value[4:8], 'little') + 1
value = value[:4] + struct.pack('<III', counter, 3, len(server)) + server + struct.pack('<I', len(bypass)) + bypass + b'\x00'*36
winreg.SetValueEx(key, self.SUBKEY, None, regtype, value)
winreg.CloseKey(key)
示例4: set_doc_author_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def set_doc_author_keys(userinitials, username):
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Office\Common\UserInfo', 0,
winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, "UserName", 0, winreg.REG_SZ, username)
winreg.SetValueEx(key, "UserInitials", 0, winreg.REG_SZ, userinitials)
except FileNotFoundError:
print("[!] Office may not be installed and initially run to create the necessary key locations. "
"Please install and open Office once to set it up.")
raise FileNotFoundError
# returns the list of playbook items to allow for the creation of the file, and if necessary, renaming it to the
# desired extension
#
# set_save_format determines the file format
# set_save_extension will be the extension compatible with the type of file you're saving.
# docm format can't be named .doc when saved by word, but it will work if renamed afterward
#
# set_extension_after_save will indicate the file needs renamed after it is saved
#
示例5: set_envvar_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [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)
示例6: get_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def get_windows_path_var(self):
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
path, _ = winreg.QueryValueEx(key, "PATH")
return path
示例7: checkstartup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def checkstartup():
# check if it is linux
if os_type in OS.UNIX_LIKE:
# check if the startup exists
if os.path.exists(home_address + "/.config/autostart/persepolis.desktop"):
return True
else:
return False
# check if it is mac
elif os_type == OS.OSX:
# OS X
if os.path.exists(home_address + "/Library/LaunchAgents/com.persepolisdm.plist"):
return True
else:
return False
# check if it is Windows
elif os_type == OS.WINDOWS:
# try to open startup key and check persepolis value
try:
aKey = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, winreg.KEY_ALL_ACCESS)
startupvalue = winreg.QueryValueEx(aKey, 'persepolis')
startup = True
except WindowsError:
startup = False
# Close the connection
winreg.CloseKey(aKey)
# if the startup enabled or disabled
if startup:
return True
if not startup:
return False
# add startup file
示例8: removestartup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def removestartup():
# check if it is linux
if os_type in OS.BSD_FAMILY:
# remove it
os.remove(home_address + "/.config/autostart/persepolis.desktop")
# check if it is mac OS
elif os_type == OS.OSX:
# OS X
if checkstartup():
os.system('launchctl unload ' + home_address +
"/Library/LaunchAgents/com.persepolisdm.plist")
os.remove(home_address +
"/Library/LaunchAgents/com.persepolisdm.plist")
# check if it is Windows
elif os_type == OS.WINDOWS:
if checkstartup():
# Connect to the startup path in Registry
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, winreg.KEY_ALL_ACCESS)
# remove persepolis from startup
winreg.DeleteValue(key, 'persepolis')
# Close connection
winreg.CloseKey(key)
示例9: delete_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
try:
key_name = self._key_for_service(service)
hkey = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS
)
winreg.DeleteValue(hkey, username)
winreg.CloseKey(hkey)
except WindowsError:
e = sys.exc_info()[1]
raise PasswordDeleteError(e)
self._delete_key_if_empty(service)
示例10: setenv
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [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)
示例11: create_registry_entry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def create_registry_entry(product, arc_version):
"""Create a registry link back to the arcgisbinding package."""
root_key = winreg.HKEY_CURRENT_USER
if product == 'Pro':
product_name = "ArcGISPro"
else:
product_name = "Desktop{}".format(arc_version)
reg_path = "SOFTWARE\\Esri\\{}".format(product_name)
package_key = 'RintegrationProPackagePath'
link_key = None
try:
full_access = (winreg.KEY_WOW64_64KEY + winreg.KEY_ALL_ACCESS)
# find the key, 64- or 32-bit we want it all
link_key = winreg.OpenKey(root_key, reg_path, 0, full_access)
except fnf_exception as error:
handle_fnf(error)
if link_key:
try:
arcpy.AddMessage("Using registry key to link install.")
binding_path = "{}\\{}".format(r_lib_path(), "arcgisbinding")
winreg.SetValueEx(link_key, package_key, 0,
winreg.REG_SZ, binding_path)
except fnf_exception as error:
handle_fnf(error)
示例12: clear
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def clear(self):
if self.listen is None:
return
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.KEY, 0, winreg.KEY_ALL_ACCESS)
value, regtype = winreg.QueryValueEx(key, self.SUBKEY)
assert regtype == winreg.REG_BINARY
counter = int.from_bytes(value[4:8], 'little') + 1
value = value[:4] + struct.pack('<II', counter, 1) + b'\x00'*44
winreg.SetValueEx(key, self.SUBKEY, None, regtype, value)
winreg.CloseKey(key)
示例13: set_startup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_ALL_ACCESS [as 別名]
def set_startup():
if plexpy.WIN_SYS_TRAY_ICON:
plexpy.WIN_SYS_TRAY_ICON.change_tray_icons()
startup_reg_path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
exe = sys.executable
if plexpy.FROZEN:
args = [exe]
else:
args = [exe, plexpy.FULL_PATH]
cmd = ' '.join(cmd_quote(arg) for arg in args).replace('python.exe', 'pythonw.exe').replace("'", '"')
if plexpy.CONFIG.LAUNCH_STARTUP:
try:
winreg.CreateKey(winreg.HKEY_CURRENT_USER, startup_reg_path)
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_reg_path, 0, winreg.KEY_WRITE)
winreg.SetValueEx(registry_key, common.PRODUCT, 0, winreg.REG_SZ, cmd)
winreg.CloseKey(registry_key)
logger.info("Added Tautulli to Windows system startup registry key.")
return True
except WindowsError as e:
logger.error("Failed to create Windows system startup registry key: %s", e)
return False
else:
# Check if registry value exists
try:
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_reg_path, 0, winreg.KEY_ALL_ACCESS)
winreg.QueryValueEx(registry_key, common.PRODUCT)
reg_value_exists = True
except WindowsError:
reg_value_exists = False
if reg_value_exists:
try:
winreg.DeleteValue(registry_key, common.PRODUCT)
winreg.CloseKey(registry_key)
logger.info("Removed Tautulli from Windows system startup registry key.")
return True
except WindowsError as e:
logger.error("Failed to delete Windows system startup registry key: %s", e)
return False