本文整理匯總了Python中winreg.CreateKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.CreateKey方法的具體用法?Python winreg.CreateKey怎麽用?Python winreg.CreateKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.CreateKey方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: config_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def config_win():
try:
import winreg as reg
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk')
reg.SetValue(key, '', reg.REG_SZ, 'URL:nzblnk')
reg.SetValueEx(key, 'URL Protocol', 0, reg.REG_SZ, '')
reg.CloseKey(key)
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk\\shell\\open\\command')
reg.SetValue(key, '', reg.REG_SZ, '"{0}" "%1"'.format(op.normpath(os.path.abspath(sys.executable))))
reg.CloseKey(key)
except (OSError, ImportError):
print(Col.FAIL + ' FAILED to setup registry link for NZBLNK scheme!' + Col.OFF)
sleep(wait_time)
sys.exit(2)
示例2: modify
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [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"):
usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
userpath = os.path.dirname(usersite)
userscripts = os.path.join(userpath, "Scripts")
else:
userscripts = None
with winreg.CreateKey(HKCU, ENV) as key:
try:
envpath = winreg.QueryValueEx(key, PATH)[0]
except OSError:
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
示例3: get_start_time
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def get_start_time(self):
'''
@summary: Get's Crypter's start time from the registry, or creates it if it
doesn't exist
@return: The time that the ransomware began it's encryption operation, in integer epoch form
'''
# Try to open registry key
try:
reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION)
start_time = winreg.QueryValueEx(reg, "")[0]
winreg.CloseKey(reg)
# If failure, create the key
except WindowsError:
start_time = int(time.time())
reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION)
winreg.SetValue(reg, "", winreg.REG_SZ, str(start_time))
winreg.CloseKey(reg)
return start_time
示例4: set_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def set_password(self, service, username, password):
"""Write the password to the registry
"""
# encrypt the password
password_encrypted = _win_crypto.encrypt(password.encode('utf-8'))
# encode with base64
password_base64 = base64.encodestring(password_encrypted)
# encode again to unicode
password_saved = password_base64.decode('ascii')
# store the password
key_name = self._key_for_service(service)
hkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER, key_name)
winreg.SetValueEx(hkey, username, 0, winreg.REG_SZ, password_saved)
示例5: windows_registry_set_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def windows_registry_set_key(key_path, value):
from winreg import CreateKey, SetValue, HKEY_CURRENT_USER, REG_SZ
with CreateKey(HKEY_CURRENT_USER, key_path) as sub_key:
SetValue(sub_key, None, REG_SZ, value)
示例6: create_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def create_key(self):
try:
self.current_key = winreg.CreateKey(self.key, self.subkey)
to_return = self._return_success(self.current_key)
except WindowsError as e:
to_return = self._return_error(str(e))
return to_return
示例7: create_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def create_key(self, key, subkey):
""" Creates a key THAT DOESN'T EXIST, we need
to keep track of the keys that we are creating
"""
self.no_restore = False
self.non_existent_path(key, subkey)
try:
return winreg.CreateKey(key, subkey)
except WindowsError as error:
self.no_restore = True
return None
示例8: disable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def disable(self):
'''
@summary: Disables Windows Task Manager
'''
key_exists = False
# Try to read the key
try:
reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION)
disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0]
winreg.CloseKey(reg)
key_exists = True
except:
pass
# If key doesn't exist, create it and set to disabled
if not key_exists:
reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER,
self.DISABLE_KEY_LOCATION)
winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000001)
winreg.CloseKey(reg)
# If enabled, disable it
elif key_exists and not disabled:
reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
self.DISABLE_KEY_LOCATION,
0,
winreg.KEY_SET_VALUE)
winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000001)
winreg.CloseKey(reg)
示例9: set_subkey
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [as 別名]
def set_subkey(self,name,value=None):
"""Create the named subkey and set its value.
There are several different ways to specify the new contents of
the named subkey:
* if 'value' is the Key class, a subclass thereof, or None, then
the subkey is created but not populated with any data.
* if 'value' is a key instance, the data from that key will be
copied into the new subkey.
* if 'value' is a dictionary, the dict's keys are interpreted as
key or value names and the corresponding entries are created
within the new subkey - nested dicts create further subkeys,
while scalar values create values on the subkey.
* any other value will be converted to a Value object and assigned
to the default value for the new subkey.
"""
self.sam |= KEY_CREATE_SUB_KEY
subkey = Key(name,self)
try:
subkey = self.get_subkey(name)
except AttributeError:
_winreg.CreateKey(self.hkey,name)
subkey = self.get_subkey(name)
if value is None:
pass
elif issubclass(type(value),type) and issubclass(value,Key):
pass
elif isinstance(value,Key):
for v in value.values():
subkey[v.name] = v
for k in value.subkeys():
subkey.set_subkey(k.name,k)
elif isinstance(value,dict):
for (nm,val) in value.items():
if isinstance(val,dict):
subkey.set_subkey(nm,val)
elif isinstance(val,Key):
subkey.set_subkey(nm,val)
elif issubclass(type(val),type) and issubclass(val,Key):
subkey.set_subkey(nm,val)
else:
subkey[nm] = val
else:
if not isinstance(value,Value):
value = Value(value)
subkey[value.name] = value
示例10: set_startup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKey [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