Advertisement
Python253

default_cmd_properties

Apr 27th, 2024 (edited)
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: default_cmd_properties.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script gathers the default Command Prompt properties and outputs them in the terminal.
  9.  
  10. Requirements:
  11.    - Python 3.x
  12.    - pygetwindow library (install via 'pip install pygetwindow')
  13.  
  14. Usage:
  15.    Run the script in a Python environment. It will automatically retrieve the default properties of the Command Prompt window and display them in the terminal.
  16.  
  17. Functions:
  18.    get_default_cmd_properties():
  19.        Retrieves the default properties of the Command Prompt window.
  20.        Returns:
  21.            dict: A dictionary containing the default properties:
  22.                - "Window Size": Tuple of width and height of the Command Prompt window.
  23.                - "Font Name": Default font name used in the Command Prompt window (Consolas).
  24.                - "Font Size": Default font size used in the Command Prompt window (12).
  25.  
  26. Example Output:
  27.    Default Command Prompt Properties:
  28.    Window Size: (993, 519)
  29.    Font Name: Consolas
  30.    Font Size: 12
  31.  
  32. Additional Notes:
  33.    - If the Command Prompt window is not found or an error occurs during retrieval, an error message will be printed.
  34. """
  35.  
  36. import winreg
  37.  
  38. def get_cmd_properties():
  39.     """
  40.    Retrieves the properties of the Command Prompt window.
  41.    
  42.    Returns:
  43.        dict: A dictionary containing the Command Prompt properties.
  44.    """
  45.     cmd_key_path = r"HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe"
  46.     cmd_properties = {}
  47.     try:
  48.         with winreg.OpenKey(winreg.HKEY_CURRENT_USER, cmd_key_path) as key:
  49.             # Iterate over the values in the registry key
  50.             for i in range(winreg.QueryInfoKey(key)[1]):
  51.                 name, value, _ = winreg.EnumValue(key, i)
  52.                 cmd_properties[name] = value
  53.         return cmd_properties
  54.     except FileNotFoundError:
  55.         print("Error: Command Prompt properties not found in the registry.")
  56.         return None
  57.  
  58. # Get Command Prompt properties
  59. cmd_properties = get_cmd_properties()
  60. if cmd_properties:
  61.     print("Command Prompt Properties:")
  62.     for name, value in cmd_properties.items():
  63.         print(f"{name}: {value}")
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement