В моем реестре есть: Software\Classes\CLSID
Но нет: {86ca1aa0-34aa-4e8b -a509-50c905bae2a2}\InprocServer32
Это код:
Код: Выделить всё
import winreg
def hive_name(hive):
if hive == winreg.HKEY_CURRENT_USER:
return "HKEY_CURRENT_USER"
elif hive == winreg.HKEY_LOCAL_MACHINE:
return "HKEY_LOCAL_MACHINE"
elif hive == winreg.HKEY_CLASSES_ROOT:
return "HKEY_CLASSES_ROOT"
elif hive == winreg.HKEY_USERS:
return "HKEY_USERS"
elif hive == winreg.HKEY_PERFORMANCE_DATA:
return "HKEY_PERFORMANCE_DATA"
elif hive == winreg.HKEY_CURRENT_CONFIG:
return "HKEY_CURRENT_CONFIG"
else:
return "UNKNOWN_HIVE"
def open_or_create_key(hive, path):
try:
# Open the registry key for reading and writing
key = winreg.OpenKey(hive, path, 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
print(f"Key opened: {hive_name(hive)}\\{path}")
except FileNotFoundError:
# Handle if the key doesn't exist
print(f"Creating key: {hive_name(hive)}\\{path}")
key = winreg.CreateKeyEx(hive, path, 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
except PermissionError:
# Handle if there are permission issues
print(f"Permission denied while accessing the key: {hive_name(hive)}\\{path}")
key = None
except Exception as e:
# Handle any other exceptions
print(f"An error occurred: {e}")
key = None
return key
def close_key(key):
if key:
winreg.CloseKey(key)
print("Key closed.")
# Test the open_or_create_key function
if __name__ == "__main__":
hive = winreg.HKEY_CURRENT_USER
path = r"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"
# Call the function with the test key
key = open_or_create_key(hive, path)
if key:
# The key was successfully opened or created
print("Test passed: Key opened or created successfully.")
close_key(key)
else:
# The key could not be opened or created
print("Test failed: Key could not be opened or created.")
Код: Выделить всё
Key opened: HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32
Test passed: Key opened or created successfully.
Key closed.
Я пробовал:
- < li>Открытие и закрытие реестра
- Перезапуск процесса проводника Windows
Подробнее здесь: https://stackoverflow.com/questions/786 ... y-registry