本文整理匯總了Python中winreg.REG_SZ屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.REG_SZ屬性的具體用法?Python winreg.REG_SZ怎麽用?Python winreg.REG_SZ使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.REG_SZ屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: config_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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: windows_group_policy_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def windows_group_policy_path():
# we know that we're running under windows at this point so it's safe to do these imports
from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ
try:
root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome")
user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir")
if type_ == REG_EXPAND_SZ:
user_data_dir = os.path.expandvars(user_data_dir)
elif type_ != REG_SZ:
return None
except OSError:
return None
return os.path.join(user_data_dir, "Default", "Cookies")
# Code adapted slightly from https://github.com/Arnie97/chrome-cookies
示例3: toggle_run_on_startup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def toggle_run_on_startup(self, is_checked):
if (self.platform == 'Windows'):
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run',
0, winreg.KEY_SET_VALUE)
if (is_checked):
path = sys.executable
winreg.SetValueEx(key, 'Blender Version Manager',
0, winreg.REG_SZ, path)
else:
try:
winreg.DeleteValue(key, 'Blender Version Manager')
except:
pass
key.Close()
self.settings.setValue('is_run_on_startup', is_checked)
示例4: __search_registry_for_run_cmd
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def __search_registry_for_run_cmd(self, *args):
"""
:param args - arguments as for winreg.OpenKey()
:returns value of the first string-type key or False if given registry does not exists
"""
try:
key = winreg.OpenKey(*args)
for i in range(1024):
try:
_, exe_cmd, _type = winreg.EnumValue(key, i)
if exe_cmd and _type == winreg.REG_SZ: # null-terminated string
return exe_cmd
except OSError: # no more data
break
except FileNotFoundError:
return None
示例5: set_doc_author_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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
#
示例6: get_start_time
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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
示例7: Reg2Py
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def Reg2Py(data, size, data_type):
if data_type == winreg.REG_DWORD:
if size == 0:
return 0
return ctypes.cast(data, ctypes.POINTER(ctypes.c_int)).contents.value
elif data_type == winreg.REG_SZ or data_type == winreg.REG_EXPAND_SZ:
return ctypes.wstring_at(data, size // 2).rstrip(u"\x00")
elif data_type == winreg.REG_MULTI_SZ:
return ctypes.wstring_at(data, size // 2).rstrip(u"\x00").split(u"\x00")
else:
if size == 0:
return None
return ctypes.string_at(data, size)
示例8: set_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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)
示例9: get_value_from_tuple
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def get_value_from_tuple(value, vtype):
if vtype == winreg.REG_SZ:
if '\0' in value:
return value[:value.index('\0')]
return value
return None
示例10: set_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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)))
示例11: _set_all_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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)))
示例12: get_value_from_tuple
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def get_value_from_tuple(value, value_type):
try:
import winreg
except ImportError:
import _winreg as winreg
if value_type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ):
if "\0" in value:
return value[: value.index("\0")]
return value
return None
示例13: windows_registry_set_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [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)
示例14: read_windows_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def read_windows_registry(self, strict=True):
"""
Load the MIME types database from Windows registry.
If strict is true, information will be added to
list of standard types, else to the list of non-standard
types.
"""
# Windows only
if not _winreg:
return
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
break
else:
if '\0' not in ctype:
yield ctype
i += 1
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
for subkeyname in enum_types(hkcr):
try:
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
# Only check file extensions
if not subkeyname.startswith("."):
continue
# raises EnvironmentError if no 'Content Type' value
mimetype, datatype = _winreg.QueryValueEx(
subkey, 'Content Type')
if datatype != _winreg.REG_SZ:
continue
self.add_type(mimetype, subkeyname, strict)
except EnvironmentError:
continue
示例15: read_windows_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import REG_SZ [as 別名]
def read_windows_registry(self, strict=True):
"""
Load the MIME types database from Windows registry.
If strict is true, information will be added to
list of standard types, else to the list of non-standard
types.
"""
# Windows only
if not _winreg:
return
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except OSError:
break
else:
if '\0' not in ctype:
yield ctype
i += 1
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
for subkeyname in enum_types(hkcr):
try:
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
# Only check file extensions
if not subkeyname.startswith("."):
continue
# raises OSError if no 'Content Type' value
mimetype, datatype = _winreg.QueryValueEx(
subkey, 'Content Type')
if datatype != _winreg.REG_SZ:
continue
self.add_type(mimetype, subkeyname, strict)
except OSError:
continue