Advertisement
Python253

disable_copilot

Mar 18th, 2024
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: disable_copilot.py
  4. # Version: 1.00
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script disables the Windows CoPilot AI feature in Windows by creating registry keys and DWORD values.
  9.  
  10. Requirements:
  11. - Python 3
  12. - Elevated Administrator Permissions
  13.  
  14. Usage:
  15. 1. Ensure the script is run with Python 3.
  16. 2. Make sure to execute the script with elevated administrator permissions.
  17. 3. Run the script to disable the CoPilot AI feature.
  18.  
  19. Registry Modification Notes:
  20. - This script creates the necessary registry keys and DWORD values to disable Windows CoPilot AI by editing the Windows registry.
  21. - It is recommended to create a backup of the registry before making any changes.
  22. """
  23.  
  24. import winreg
  25.  
  26. # Function to create the registry keys
  27. def create_registry_key(root_key, key_path):
  28.     """
  29.    Create a registry key.
  30.  
  31.    Args:
  32.        root_key (HKEY): The root key of the registry.
  33.        key_path (str): The path to the registry key.
  34.  
  35.    Raises:
  36.        Exception: If an error occurs while creating the registry key.
  37.    """
  38.     try:
  39.         with winreg.CreateKey(root_key, key_path) as key:
  40.             print(f"Created registry key: {key_path}")
  41.     except Exception as e:
  42.         print(f"Error creating registry key: {e}")
  43.  
  44.  
  45. # Function to create the dword values
  46. def create_registry_value(root_key, key_path, value_name, value_data):
  47.     """
  48.    Create a DWORD registry value.
  49.  
  50.    Args:
  51.        root_key (HKEY): The root key of the registry.
  52.        key_path (str): The path to the registry key.
  53.        value_name (str): The name of the registry value.
  54.        value_data (int): The data of the DWORD registry value.
  55.  
  56.    Raises:
  57.        Exception: If an error occurs while creating the registry value.
  58.    """
  59.     try:
  60.         with winreg.OpenKey(root_key, key_path, 0, winreg.KEY_WRITE) as key:
  61.             winreg.SetValueEx(key, value_name, 0, winreg.REG_DWORD, value_data)
  62.             print(f"Created registry value: {value_name} = {value_data}")
  63.     except Exception as e:
  64.         print(f"Error creating registry value: {e}")
  65.  
  66. # Function to disable the CoPilot AI
  67. def disable_copilot():
  68.     """
  69.    Disable the Windows CoPilot AI feature by creating registry keys and DWORD values.
  70.  
  71.    The function iterates through specified registry key paths and creates the necessary keys and DWORD values
  72.    to disable the Windows CoPilot AI feature. It prints messages indicating the success or failure of each operation.
  73.  
  74.    Note:
  75.    - Elevated administrator permissions are required to edit the registry.
  76.    """
  77.     key_paths = [
  78.         (winreg.HKEY_CURRENT_USER, r"Software\Policies\Microsoft\Windows\WindowsCopilot"),
  79.         (winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot")
  80.     ]
  81.    
  82.     value_data = 1
  83.    
  84.     for root_key, key_path in key_paths:
  85.         create_registry_key(root_key, key_path)
  86.         create_registry_value(root_key, key_path, "TurnOffWindowsCopilot", value_data)
  87.  
  88. if __name__ == "__main__":
  89.     disable_copilot()
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement