本文整理汇总了Python中_winreg.KEY_WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python _winreg.KEY_WRITE属性的具体用法?Python _winreg.KEY_WRITE怎么用?Python _winreg.KEY_WRITE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类_winreg
的用法示例。
在下文中一共展示了_winreg.KEY_WRITE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def save(self):
if USE_WINDOWS:
import _winreg
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, self.keyname,
sam=_winreg.KEY_SET_VALUE | _winreg.KEY_WRITE)
except:
key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, self.keyname)
try:
for k, v in self.values.iteritems():
_winreg.SetValueEx(key, str(k), 0, _winreg.REG_SZ, str(v))
finally:
key.Close()
else:
d = os.path.dirname(self.filename)
if not os.path.isdir(d):
os.makedirs(d)
f = open(self.filename, 'w')
try:
data = '\n'.join(["%s=%s" % (k,v)
for k,v in self.values.iteritems()])
f.write(data)
finally:
f.close()
示例2: registry_key
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def registry_key(key, subkey, value):
"""
Create a new Windows Registry Key in HKEY_CURRENT_USER
`Required`
:param str key: primary registry key name
:param str subkey: registry key sub-key name
:param str value: registry key sub-key value
Returns True if successful, otherwise False
"""
try:
import _winreg
reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value)
_winreg.CloseKey(reg_key)
return True
except Exception as e:
log(e)
return False
示例3: write_block
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def write_block(self, bucket_id, value_id, data=""):
"""Described in parent class"""
try:
value_name = self._get_value_name(
bucket_id, value_id)
except BucketValueMissingException:
logger.debug(
"value with id does not exist in specified bucket." +
" generating a new value name for bucket id %s" % bucket_id)
value_name = self._generate_value_name(bucket_id)
logger.debug("generated a new value name in bucket id %s: %s" % (
bucket_id, value_name))
with self._get_bucket_key(bucket_id, _winreg.KEY_WRITE) as key:
_winreg.SetValueEx(key, value_name, 0,
_winreg.REG_BINARY, data)
return RegistryStorageProvider.value_name_to_value_id(value_name)
示例4: install
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def install():
if check_installed() is False:
runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
winreg.KEY_WRITE)
winreg.SetValueEx(runkey, "Px", 0, winreg.REG_EXPAND_SZ,
get_script_cmd())
winreg.CloseKey(runkey)
pprint("Px installed successfully")
else:
pprint("Px already installed")
sys.exit()
示例5: uninstall
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def uninstall():
if check_installed() is True:
runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
winreg.KEY_WRITE)
winreg.DeleteValue(runkey, "Px")
winreg.CloseKey(runkey)
pprint("Px uninstalled successfully")
else:
pprint("Px is not installed")
sys.exit()
###
# Attach/detach console
示例6: set_value
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def set_value(self, value_name, value):
with winreg.CreateKeyEx(self._root, self.subkey, 0, winreg.KEY_WRITE | self._flags) as key:
if value is None:
winreg.DeleteValue(key, value_name)
elif isinstance(value, str):
winreg.SetValueEx(key, value_name, 0, winreg.REG_SZ, value)
else:
raise TypeError('cannot write {} to registry'.format(type(value)))
示例7: _set_all_values
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def _set_all_values(self, rootkey, name, info, errors):
with winreg.CreateKeyEx(rootkey, name, 0, winreg.KEY_WRITE | self._flags) as key:
for k, v in info:
if isinstance(v, PythonWrappedDict):
self._set_all_values(key, k, v._items(), errors)
elif isinstance(v, dict):
self._set_all_values(key, k, v.items(), errors)
elif v is None:
winreg.DeleteValue(key, k)
elif isinstance(v, str):
winreg.SetValueEx(key, k, 0, winreg.REG_SZ, v)
else:
errors.append('cannot write {} to registry'.format(type(v)))
示例8: open_key
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def open_key(self, key, subkey):
""" Opens a key
"""
try:
return winreg.OpenKey(key, subkey, 0, winreg.KEY_WRITE)
except:
return None
示例9: windows_persistence
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def windows_persistence():
import _winreg
from _winreg import HKEY_CURRENT_USER as HKCU
run_key = r'Software\Microsoft\Windows\CurrentVersion\Run'
bin_path = sys.executable
try:
reg_key = _winreg.OpenKey(HKCU, run_key, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(reg_key, 'br', 0, _winreg.REG_SZ, bin_path)
_winreg.CloseKey(reg_key)
return True, 'HKCU Run registry key applied'
except WindowsError:
return False, 'HKCU Run registry key failed'
示例10: srOXhtoTWVPOQTAFQsEjXglmECQYMydH
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def srOXhtoTWVPOQTAFQsEjXglmECQYMydH():
import _winreg
from _winreg import HKEY_CURRENT_USER as HKCU
ejhEOFlPViXKPUHKJhcSyqqQjSUcagli = r'Software\Microsoft\Windows\CurrentVersion\Run'
MtcFrCNqZIqaQyIxdGTfhTosybVfegHt = sys.executable
try:
SCyNiWCgkJlizIsydlByszPSbHjrsmmo = _winreg.OpenKey(HKCU, ejhEOFlPViXKPUHKJhcSyqqQjSUcagli, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(SCyNiWCgkJlizIsydlByszPSbHjrsmmo, 'br', 0, _winreg.REG_SZ, MtcFrCNqZIqaQyIxdGTfhTosybVfegHt)
_winreg.CloseKey(SCyNiWCgkJlizIsydlByszPSbHjrsmmo)
return True, 'HKCU Run registry key applied'
except WindowsError:
return False, 'HKCU Run registry key failed'
示例11: add_registry_keys
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def add_registry_keys():
for key in get_local_machine_registry_subkeys(KHRONOS_REG_PATH):
if key is not None:
key = RegistryKey(key[0], key[2], key[1])
if key in KEYS_NEEDED:
KEYS_NEEDED.remove(key)
else:
# print("?: "+str(key))
pass
# print("No keys left\nKeys to add: "+str(KEYS_NEEDED))
for key_needed in KEYS_NEEDED:
try:
try:
subkey = winreg.CreateKeyEx(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_CREATE_SUB_KEY)
except WindowsError as error:
print("Couldn't create subkeys at: %s\tReason: %s" % (KHRONOS_REG_PATH, error))
exit(1)
finally:
subkey.Close()
with winreg.OpenKey(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_WRITE) as key:
winreg.SetValueEx(key, key_needed.name, 0, key_needed.data_type, key_needed.value)
# print("+"+str(key_needed))
except WindowsError as error:
print("Couldn't create (%s)\tReason: %s" % (key_needed, error))
exit(1)
# TODO: How to Enumerate Vendor ICDs on Windows: https://github.com/KhronosGroup/OpenCL-Docs/blob/master/ext/cl_khr_icd.txt#L68
# SEARCH_HIVE=winreg.HKEY_LOCAL_MACHINE
示例12: Finish
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def Finish(self):
"""
This will be called inside the thread when it finishes. It will even
be called if the thread exits through an exception.
"""
self.abort = True
self.lock.acquire()
if self.dll:
self.dll.IR_Close(self.hwnd, 0);
#print "Irremote is stopped"
if self.timerInit :
self.timerInit.cancel()
#print "Init aborted"
if self.hwnd:
windll.user32.KillTimer(self.hwnd, 1)
DestroyWindow(self.hwnd)
UnregisterClass(self.wc.lpszClassName, self.hinst)
if self.defaultPollTime != -1 :
regHandle = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\hauppauge\IR',
0,
_winreg.KEY_WRITE | _winreg.KEY_READ
)
_winreg.SetValueEx( regHandle, 'PollRate', 0, _winreg.REG_DWORD, int(self.defaultPollTime) )
_winreg.CloseKey( regHandle )
self.lock.release()
示例13: __call__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def __call__(
self,
key,
subkey,
valueName,
action,
keyType,
newValue,
disableParsing=False
):
if not disableParsing:
newValue = eg.ParseString(newValue)
if not key:
self.PrintError(self.text2.noKeyError)
return 0
if not subkey:
self.PrintError(self.text2.noSubkeyError)
return 0
if not valueName:
self.PrintError(self.text2.noValueNameError)
return 0
#try to get handle
try:
if action == 0:
regHandle = _winreg.CreateKey(key, subkey)
else:
regHandle = _winreg.OpenKey(
key,
subkey,
0,
_winreg.KEY_WRITE | _winreg.KEY_READ
)
except EnvironmentError, exc:
if action != 1:
eg.PrintError(self.text2.keyOpenError + ": " + str(exc))
return 0
#getting old value
示例14: set_startup
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [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
示例15: PostInit
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import KEY_WRITE [as 别名]
def PostInit( self ) :
self.lock.acquire()
if self.abort :
self.lock.release()
return
self.timerInit = Timer( 60.0, self.OnPostInitTimeOut) # Init timeout timer
self.timerInit.start()
returnVal = False
if ( not self.useDefaultPollTime ) :
regHandle = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\hauppauge\IR',
0,
_winreg.KEY_WRITE | _winreg.KEY_READ
)
self.defaultPollTime = int( _winreg.QueryValueEx(regHandle, 'PollRate')[0] )
_winreg.SetValueEx( regHandle, 'PollRate', 0, _winreg.REG_DWORD, int(self.pollTime) )
returnVal = self.IR_Open(self.hwnd, 0, 0, 0);
_winreg.SetValueEx( regHandle, 'PollRate', 0, _winreg.REG_DWORD, int(self.defaultPollTime) )
_winreg.CloseKey( regHandle )
self.defaultPollTime = -1
else :
returnVal = self.IR_Open(self.hwnd, 0, 0, 0);
self.timerInit.cancel()
if not self.initTerminated :
if not returnVal and not self.initTerminated :
self.plugin.PrintError("Couldn't start the Hauppauge remote control")
self.Stop()
self.plugin.TriggerEvent("InitError")
else :
#print "Irremote is started"
pass
del self.timerInit
self.timerInit = None
self.lock.release()