Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: open_optional_features.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script facilitates the opening of the "Turn Windows features on or off" dialog on Windows systems.
- It does so by emulating key presses to navigate through the Windows Run dialog and enter the command to open the features dialog.
- Requirements:
- - Python 3.x
- - Windows operating system
- Usage:
- - Run the script in a Python environment compatible with the specified requirements.
- Functions:
- - press_key(key): Simulates pressing a key using ctypes.
- - type_string(string): Simulates typing a string by pressing individual keys.
- - simulate_key_strokes(): Simulates key strokes to open the Run dialog and type 'optionalfeatures' to open the 'Turn Windows features on or off' dialog.
- Additional Notes:
- - The script utilizes ctypes to interact with the Windows API and simulate key presses.
- - Ensure that the script is executed with the necessary permissions to emulate key presses and open system dialogs.
- """
- import subprocess
- import os
- import sys
- import time
- import ctypes
- def press_key(key):
- """
- Simulate pressing a key using ctypes.
- Parameters:
- key (int): The virtual key code of the key to be pressed.
- """
- ctypes.windll.user32.keybd_event(key, 0, 0, 0)
- time.sleep(0.05)
- ctypes.windll.user32.keybd_event(key, 0, 2, 0)
- def type_string(string):
- """
- Simulate typing a string by pressing individual keys.
- Parameters:
- string (str): The string to be typed.
- """
- for char in string:
- key_code = ord(char.upper())
- press_key(key_code)
- def simulate_key_strokes():
- """
- Simulate key strokes to open the Run dialog and type 'optionalfeatures' to open the 'Turn Windows features on or off' dialog.
- """
- # Simulate pressing Win + R to open Run dialog
- press_key(0x5B) # VK_LWIN
- press_key(0x52) # 'R'
- type_string("un") # Complete the simulated typing of "run"
- # Hit Enter
- press_key(0x0D) # 'Enter'
- time.sleep(0.5) # Give time for Run dialog to appear
- # Simulate typing "optionalfeatures"
- type_string("optionalfeatures")
- # Hit Enter
- press_key(0x0D) # 'Enter'
- if __name__ == "__main__":
- simulate_key_strokes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement