本文整理匯總了Python中win32api.RegOpenKeyEx方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.RegOpenKeyEx方法的具體用法?Python win32api.RegOpenKeyEx怎麽用?Python win32api.RegOpenKeyEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32api
的用法示例。
在下文中一共展示了win32api.RegOpenKeyEx方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_keys
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def read_keys(base, key):
"""Return list of registry keys."""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
L = []
i = 0
while 1:
try:
k = RegEnumKey(handle, i)
except RegError:
break
L.append(k)
i = i + 1
return L
示例2: read_values
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def read_values(base, key):
"""Return dict of registry keys and values.
All names are converted to lowercase.
"""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
d = {}
i = 0
while 1:
try:
name, value, type = RegEnumValue(handle, i)
except RegError:
break
name = name.lower()
d[convert_mbcs(name)] = convert_mbcs(value)
i = i + 1
return d
示例3: check_registry
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def check_registry():
for key_string in reg_paths:
parts = key_string.split("\\")
hive = parts[0]
key_string = "\\".join(parts[1:])
try:
keyh = win32api.RegOpenKeyEx(getattr(win32con, hive), key_string, 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
#print "Can't open: " + hive + "\\" + key_string
continue
sd = win32api.RegGetKeySecurity(keyh, win32security.DACL_SECURITY_INFORMATION | win32security.OWNER_SECURITY_INFORMATION)
weak_perms = check_weak_write_perms_by_sd(hive + "\\" + key_string, 'reg', sd)
if weak_perms:
vprint(hive + "\\" + key_string)
#print weak_perms
if verbose == 0:
sys.stdout.write(".")
save_issue("WPC003", "writable_reg_paths", weak_perms)
# print_weak_perms("x", weak_perms)
print
# TODO save_issue("WPC009", "writable_eventlog_key", weak_perms) # weak perms on event log reg key
示例4: get_user_paths
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def get_user_paths():
try:
keyh = win32api.RegOpenKeyEx(win32con.HKEY_USERS, None , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
return 0
paths = []
subkeys = win32api.RegEnumKeyEx(keyh)
for subkey in subkeys:
try:
subkeyh = win32api.RegOpenKeyEx(keyh, subkey[0] + "\\Environment" , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
pass
else:
subkey_count, value_count, mod_time = win32api.RegQueryInfoKey(subkeyh)
try:
path, type = win32api.RegQueryValueEx(subkeyh, "PATH")
paths.append((subkey[0], path))
except:
pass
return paths
示例5: get_system_path
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def get_system_path():
# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
key_string = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
try:
keyh = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, key_string , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
return None
try:
path, type = win32api.RegQueryValueEx(keyh, "PATH")
return path
except:
return None
#name=sys.argv[1]
#if not os.path.exists(name):
#print name, "does not exist!"
#sys.exit()
示例6: read_keys
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def read_keys(base, key):
"""Return list of registry keys."""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
L = []
i = 0
while True:
try:
k = RegEnumKey(handle, i)
except RegError:
break
L.append(k)
i += 1
return L
示例7: read_values
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def read_values(base, key):
"""Return dict of registry keys and values.
All names are converted to lowercase.
"""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
d = {}
i = 0
while True:
try:
name, value, type = RegEnumValue(handle, i)
except RegError:
break
name = name.lower()
d[convert_mbcs(name)] = convert_mbcs(value)
i += 1
return d
示例8: deleteKey
# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import RegOpenKeyEx [as 別名]
def deleteKey(self, hKey, subKey):
"""
Recursively remove registry keys.
"""
try:
hKey = win32api.RegOpenKeyEx(hKey, subKey, 0,
win32con.KEY_ALL_ACCESS)
try:
while True:
s = win32api.RegEnumKey(hKey, 0)
self.deleteKey(hKey, s)
print("CleanupRegistry: Removing sub-key '{}'".format(s))
win32api.RegDeleteKey(hKey, s)
except win32api.error:
pass
finally:
win32api.RegCloseKey(hKey)
except:
print("Warning: Unable to open registry key!")
pass