Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: default_powershell_properties.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script gathers the default PowerShell properties and outputs them in the terminal.
- Requirements:
- - Python 3.x
- - Windows operating system
- Usage:
- Run the script in a Python environment. It will automatically retrieve the default properties of the PowerShell window and display them in the terminal.
- Functions:
- get_powershell_properties():
- Retrieves the default properties of the PowerShell window.
- Returns:
- dict: A dictionary containing the default properties:
- - "Window Size": Tuple of width and height of the PowerShell window.
- - "Font Name": Default font name used in the PowerShell window (Consolas).
- - "Font Size": Default font size used in the PowerShell window (12).
- Example Output:
- - 64-bit PowerShell Console Properties:
- - ScreenBufferSize: 11806479
- - WindowSize: 11796555
- - FontSize: 786432
- - FaceName: Consolas
- - FontWeight: 400
- - QuickEdit: 1
- - ScreenColors: 2
- Additional Notes:
- - If the PowerShell window is not found or an error occurs during retrieval, an error message will be printed.
- """
- import winreg
- def get_console_properties(key_path):
- """
- Retrieves the properties of the specified console from the registry.
- Parameters:
- key_path (str): The registry key path.
- Returns:
- dict: A dictionary containing the console properties if found, otherwise None.
- """
- console_properties = {}
- try:
- with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path) as key:
- # Iterate over the values in the registry key
- for i in range(winreg.QueryInfoKey(key)[1]):
- name, value, _ = winreg.EnumValue(key, i)
- console_properties[name] = value
- return console_properties
- except FileNotFoundError:
- return None
- # Define the registry paths for both 32-bit and 64-bit PowerShell consoles
- powershell_32bit_key_path = r"HKEY_CURRENT_USER\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe"
- powershell_64bit_key_path = r"HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe"
- # Get properties for the 64-bit PowerShell console
- powershell_64bit_properties = get_console_properties(powershell_64bit_key_path)
- # Get properties for the 32-bit PowerShell console if 64-bit not found
- if powershell_64bit_properties is None:
- print("64-bit PowerShell Console not found. Checking for 32-bit PowerShell Console...")
- powershell_32bit_properties = get_console_properties(powershell_32bit_key_path)
- # Display the properties for the 32-bit PowerShell console if found
- if powershell_32bit_properties:
- print("32-bit PowerShell Console Properties:")
- for name, value in powershell_32bit_properties.items():
- print(f"{name}: {value}")
- else:
- print("32-bit PowerShell Console not found.")
- else:
- print("64-bit PowerShell Console Properties:")
- for name, value in powershell_64bit_properties.items():
- print(f"{name}: {value}")
Add Comment
Please, Sign In to add comment