Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: toggle_dev_mode.py
- # Version: 1.00
- # Author: Jeoi Reqi
- """
- This script modifies the Windows registry to toggle Developer Mode on or off.
- It checks if the registry key exists and creates it if not.
- Then, it prompts the user to enable or disable Developer Mode & modifies the registry accordingly.
- Error messages are displayed if any issues arise.
- Requirements:
- - Python 3.x
- - Windows 10+
- Functions:
- - check_registry_key(key_path) : Checks if the specified registry key exists.
- - create_registry_key(key_path): Creates the specified registry key.
- - toggle_developer_mode(enable): Toggles Developer Mode on or off by setting a registry value.
- Usage:
- 1. Run the script using Python 3.x.
- 2. Follow the on-screen prompts to enable or disable Developer Mode.
- 3. Verify the registry for the changes.
- Additional Notes:
- - This script modifies the Windows registry, but should not require administrator privileges.
- - Use caution when modifying the registry, as incorrect changes can cause system instability.
- - Compatible with Windows 10+ operating systems.
- """
- import winreg
- def check_registry_key(key_path):
- """
- Check if the registry key exists.
- Args:
- key_path (str): The path of the registry key to check.
- Returns:
- bool: True if the registry key exists, False otherwise.
- """
- try:
- winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_READ)
- return True
- except FileNotFoundError:
- return False
- def create_registry_key(key_path):
- """
- Create a registry key.
- Args:
- key_path (str): The path of the registry key to create.
- Returns:
- None
- Raises:
- Exception: If an error occurs while creating the registry key.
- """
- try:
- winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, key_path)
- except Exception as e:
- raise Exception(f"Error creating registry key: {e}")
- def toggle_developer_mode(enable):
- """
- Toggle Developer Mode on or off by setting a registry value.
- Args:
- enable (bool): True to enable Developer Mode, False to disable.
- Returns:
- None
- Raises:
- FileNotFoundError: If the registry key is not found.
- Exception: If an error occurs while setting the registry value or creating the registry key.
- """
- key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
- value_name = "AllowDevelopmentWithoutDevLicense"
- # Check if the registry key exists, create it if it doesn't
- if not check_registry_key(key_path):
- create_registry_key(key_path)
- # Open the registry key
- try:
- key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_WRITE)
- except FileNotFoundError:
- raise FileNotFoundError("Error: Could not find the registry key.")
- # Set the DWORD value
- try:
- value_data = 1 if enable else 0
- winreg.SetValueEx(key, value_name, 0, winreg.REG_DWORD, value_data)
- print(f"\nDeveloper Mode {'Enabled' if enable else 'Disabled'}.\n")
- except Exception as e:
- raise Exception(f"Error setting registry value: {e}")
- finally:
- winreg.CloseKey(key)
- if __name__ == "__main__":
- while True:
- choice = input(
- """
- -----------------------------------------------------------------------------
- ::VERIFY PATH::
- [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock]
- -----------------------------------------------------------------------------
- \t\t::OPTIONS::
- \t\t1: Enable Developer Mode
- \t\t0: Disable Developer Mode
- \t\tMake Your Selection (1 or 0):
- """
- )
- if choice in ("1", "0"):
- toggle_developer_mode(int(choice))
- break
- else:
- print("\nInvalid choice. Please enter either 1 or 0.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement