Advertisement
Python253

advanced_mega_registry_toggle

Apr 24th, 2024
2,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: advanced_mega_registry_toggle.py
  4. # Version: 1.00
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script manages Windows registry settings related to system configurations.
  9. It provides functions to retrieve the current value of specific registry entries and set them to a new value.
  10. If the registry does not exist, it will be created and set to 'Disabled'.
  11.  
  12. Functions:
  13. 1. get_registry_value(value_name):
  14.   - Retrieves the current value of a specified registry entry.
  15.  
  16. 2. set_registry_value(value_name, value_data):
  17.   - Sets a registry entry to a specified value.
  18.  
  19. 3. main():
  20.   - Orchestrates the execution flow, displaying current registry values, accepting user input to toggle them, and updating the registry accordingly.
  21.  
  22. Requirements:
  23. - Python3.x
  24. - Windows 10+
  25.  
  26. Usage:
  27. 1. Ensure Python3 is installed on your Windows system.
  28. 2. Run the script from the command line or terminal.
  29. 3. Follow the on-screen instructions to view and toggle registry values.
  30.  
  31. Additional Notes:
  32. - Exercise caution when modifying registry values to avoid system instability or data loss.
  33. - Always back up important data and registry settings before making any modifications.
  34. - Use this script responsibly and at your own risk.
  35. - The author and contributors are not liable for any damage caused by its usage.
  36. """
  37.  
  38. import subprocess
  39.  
  40.  
  41. def get_registry_value(value_name):
  42.     """
  43.    Get the current value of a registry value.
  44.  
  45.    Args:
  46.        value_name (str): Name of the registry value.
  47.  
  48.    Returns:
  49.        int: Current data value of the registry value.
  50.    """
  51.     result = subprocess.run(
  52.         [
  53.             "reg",
  54.             "query",
  55.             "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
  56.             "/v",
  57.             value_name,
  58.         ],
  59.         capture_output=True,
  60.         text=True,
  61.     )
  62.     if "REG_DWORD" in result.stdout:
  63.         lines = result.stdout.strip().split("\n")
  64.         for line in lines:
  65.             if "REG_DWORD" in line:
  66.                 parts = line.split()
  67.                 return int(parts[-1], 16)  # Convert hexadecimal to decimal
  68.     return None
  69.  
  70.  
  71. def create_registry_entry(value_name, value_data):
  72.     """
  73.    Create a new registry entry with the specified value.
  74.  
  75.    Args:
  76.        value_name (str): Name of the registry value.
  77.        value_data (int): Data for the new registry value.
  78.  
  79.    Returns:
  80.        None
  81.    """
  82.     subprocess.run(
  83.         [
  84.             "reg",
  85.             "add",
  86.             "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
  87.             "/v",
  88.             value_name,
  89.             "/t",
  90.             "REG_DWORD",
  91.             "/d",
  92.             str(value_data),
  93.             "/f",
  94.         ],
  95.         stdout=subprocess.DEVNULL,
  96.         stderr=subprocess.DEVNULL,
  97.     )
  98.  
  99.  
  100. # Dictionary mapping registry value names to their default data values
  101. DEFAULT_VALUES = {
  102.     "AutoCheckSelect": get_registry_value("AutoCheckSelect"),
  103.     "DisablePreviewDesktop": get_registry_value("DisablePreviewDesktop"),
  104.     "DontPrettyPath": get_registry_value("DontPrettyPath"),
  105.     "EnableSnapAssistFlyout": get_registry_value("EnableSnapAssistFlyout"),
  106.     "Filter": get_registry_value("Filter"),
  107.     "HideFileExt": get_registry_value("HideFileExt"),
  108.     "HideIcons": get_registry_value("HideIcons"),
  109.     "Hidden": get_registry_value("Hidden"),
  110.     "IconsOnly": get_registry_value("IconsOnly"),
  111.     "ListviewAlphaSelect": get_registry_value("ListviewAlphaSelect"),
  112.     "ListviewShadow": get_registry_value("ListviewShadow"),
  113.     "MapNetDrvBtn": get_registry_value("MapNetDrvBtn"),
  114.     "MMTaskbarGlomLevel": get_registry_value("MMTaskbarGlomLevel"),
  115.     "NavPaneShowAllFolders": get_registry_value("NavPaneShowAllFolders"),
  116.     "PerformedOneTimeHideOfShowDesktopButtonForCopilot": get_registry_value(
  117.         "PerformedOneTimeHideOfShowDesktopButtonForCopilot"
  118.     ),
  119.     "ReindexedProfile": get_registry_value("ReindexedProfile"),
  120.     "SeparateProcess": get_registry_value("SeparateProcess"),
  121.     "ServerAdminUI": get_registry_value("ServerAdminUI"),
  122.     "ShowCortanaButton": get_registry_value("ShowCortanaButton"),
  123.     "ShowCompColor": get_registry_value("ShowCompColor"),
  124.     "ShowCopilotButton": get_registry_value("ShowCopilotButton"),
  125.     "ShowInfoTip": get_registry_value("ShowInfoTip"),
  126.     "ShowSecondsInSystemClock": get_registry_value("ShowSecondsInSystemClock"),
  127.     "ShowStatusBar": get_registry_value("ShowStatusBar"),
  128.     "ShowSuperHidden": get_registry_value("ShowSuperHidden"),
  129.     "ShowTypeOverlay": get_registry_value("ShowTypeOverlay"),
  130.     "StartMenuInit": get_registry_value("StartMenuInit"),
  131.     "StartMigratedBrowserPin": get_registry_value("StartMigratedBrowserPin"),
  132.     "StartShownOnUpgrade": get_registry_value("StartShownOnUpgrade"),
  133.     "Start_TrackProgs": get_registry_value("Start_TrackProgs"),
  134.     "TaskbarAl": get_registry_value("TaskbarAl"),
  135.     "TaskbarAnimations": get_registry_value("TaskbarAnimations"),
  136.     "TaskbarBadges": get_registry_value("TaskbarBadges"),
  137.     "TaskbarDa": get_registry_value("TaskbarDa"),
  138.     "TaskbarFlashing": get_registry_value("TaskbarFlashing"),
  139.     "TaskbarGlomLevel": get_registry_value("TaskbarGlomLevel"),
  140.     "TaskbarMigratedBrowserPin": get_registry_value("TaskbarMigratedBrowserPin"),
  141.     "TaskbarMn": get_registry_value("TaskbarMn"),
  142.     "TaskbarSd": get_registry_value("TaskbarSd"),
  143.     "TaskbarSi": get_registry_value("TaskbarSi"),
  144.     "TaskbarSizeMove": get_registry_value("TaskbarSizeMove"),
  145.     "TaskbarSmallIcons": get_registry_value("TaskbarSmallIcons"),
  146.     "TaskbarAutoHideInTabletMode": get_registry_value("TaskbarAutoHideInTabletMode"),
  147.     "WebView": get_registry_value("WebView"),
  148.     "WinXMigrationLevel": get_registry_value("WinXMigrationLevel"),
  149. }
  150.  
  151.  
  152. def set_registry_value(value_name, value_data):
  153.     """
  154.    Set a registry value.
  155.  
  156.    Args:
  157.        value_name (str): Name of the registry value.
  158.        value_data (int): Data to set for the registry value.
  159.  
  160.    Returns:
  161.        None
  162.    """
  163.     subprocess.run(
  164.         [
  165.             "reg",
  166.             "add",
  167.             "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
  168.             "/v",
  169.             value_name,
  170.             "/t",
  171.             "REG_DWORD",
  172.             "/d",
  173.             str(value_data),
  174.             "/f",
  175.         ],
  176.         stdout=subprocess.DEVNULL,
  177.         stderr=subprocess.DEVNULL,
  178.     )
  179.  
  180.  
  181. def main():
  182.     sorted_values = sorted(DEFAULT_VALUES.items(), key=lambda x: x[0])
  183.     max_name_length = max(len(name) for name, _ in sorted_values)
  184.  
  185.     print("\n\n\t\t::ADVANCED MEGA REGISTRY TOGGLE::\n\n")
  186.     for idx, (name, default_value) in enumerate(sorted_values, start=1):
  187.         idx_str = f"{idx:02d}"  # Preface single-digit option numbers with a 0
  188.         current_value = get_registry_value(name)
  189.         if current_value is not None:
  190.             state = "Enabled" if current_value else "Disabled"
  191.             print(f"{idx_str}: {name.ljust(max_name_length)}: {state}")
  192.         else:
  193.             print(f"{idx_str}: {name.ljust(max_name_length)}: Not found")
  194.  
  195.     print("\nEnter the number of the option to toggle (or type '0' to quit):")
  196.     while True:
  197.         choice = input("> ")
  198.         if choice == "0":
  199.             print("\n\tExiting Program...\tGoodBye!")
  200.             break
  201.         try:
  202.             choice = int(choice)
  203.             if choice < 1 or choice > len(DEFAULT_VALUES):
  204.                 print(
  205.                     "\nInvalid option. Please enter a number between 1 and",
  206.                     len(DEFAULT_VALUES),
  207.                 )
  208.                 continue
  209.         except ValueError:
  210.             print("\nInvalid input. Please enter a number or '0' to quit.\n")
  211.             continue
  212.  
  213.         # Toggle the selected option
  214.         value_name = sorted_values[choice - 1][0]
  215.         current_value = get_registry_value(value_name)
  216.         if current_value is not None:
  217.             new_value = 1 if current_value == 0 else 0
  218.             set_registry_value(value_name, new_value)
  219.             print(f"{value_name}: {'Enabled' if new_value else 'Disabled'}\n")
  220.         else:
  221.             # If registry entry doesn't exist, create it with default value 0
  222.             create_registry_entry(value_name, 0)
  223.             print(f"{value_name}: Created and set to 'Disabled'\n")
  224.  
  225.  
  226. if __name__ == "__main__":
  227.     main()
  228.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement