Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: win_env_var_explorer2.py
- # Version: 1.0.1
- # Author: Jeoi Reqi
- """
- This script allows users to explore and display Windows environment variables grouped by categories.
- Users can navigate through a menu to select a category of environment variables and then choose a specific variable
- within that category to display its current value. The script provides a user-friendly interface for interacting with
- environment variables, making it easier for users to manage and understand their Windows environment configuration.
- Additionally, users can select all categories to display and save the output data from all variables within each category to a text file.
- Requirements:
- - Python 3
- - Windows operating system
- Usage:
- - Run the script using Python 3 in a Windows environment.
- Additional Notes:
- - Ensure that Python 3 is installed on your system.
- - This script provides read-only access to environment variables and does not modify them.
- - Output data is saved to 'environment_output.txt' in the current working directory.
- """
- import os
- # Dictionary of environment variables by category
- variables = {
- "System Information": {
- 1: "ALLUSERSPROFILE",
- 2: "COMPUTERNAME",
- 3: "NUMBER_OF_PROCESSORS",
- 4: "OS",
- 5: "PROCESSOR_ARCHITECTURE",
- 6: "SYSTEMDRIVE",
- 7: "SYSTEMROOT",
- 8: "WINDIR"
- },
- "User Information": {
- 1: "APPDATA",
- 2: "HOMEDRIVE",
- 3: "HOMEPATH",
- 4: "LOCALAPPDATA",
- 5: "USERDOMAIN",
- 6: "USERNAME",
- 7: "USERPROFILE"
- },
- "File Paths": {
- 1: "CD",
- 2: "CommonProgramFiles",
- 3: "COMMONPROGRAMFILES(x86)",
- 4: "ProgramData",
- 5: "ProgramFiles",
- 6: "ProgramFiles(x86)",
- 7: "ProgramW6432",
- 8: "PSModulePath",
- 9: "Public",
- 10: "TEMP",
- 11: "TMP"
- },
- "Network": {
- 1: "ClientName",
- 2: "LOGONSERVER",
- 3: "HOMESHARE",
- 4: "OneDrive",
- 5: "OneDriveCommercial",
- 6: "OneDriveConsumer",
- 7: "UserDnsDomain",
- 8: "%SessionName%"
- },
- "Command Interpreter": {
- 1: "COMSPEC",
- 2: "CMDEXTVERSION",
- 3: "CMDCMDLINE",
- 4: "PROMPT"
- },
- "Date and Time": {
- 1: "DATE",
- 2: "TIME"
- },
- "Miscellaneous": {
- 1: "ERRORLEVEL",
- 2: "PATHEXT",
- 3: "RANDOM"
- }
- }
- # Function to save environment output to a text file
- def save_environment_output(output_data):
- with open("environment_output.txt", "w") as f:
- for category, data in output_data.items():
- f.write(f"{category}:\n")
- for variable, value in data.items():
- f.write(f"{variable}: {value}\n")
- f.write("\n")
- # Main loop
- while True:
- # Display categories menu
- print("\nChoose a category of environment variables (type '0' to exit):\n")
- for num, category in enumerate(variables.keys(), 1):
- print(f"{num:02}. {category}")
- print(f"{len(variables) + 1:02}. Select all & save the output to file.")
- # Get user input for category choice
- category_choice = input("\nEnter the number of the category you want to explore: ")
- # Exit if category choice is '0'
- if category_choice == '0':
- print("\nExiting...\tGoodBye!\n")
- break
- # Validate category choice
- if category_choice.isdigit() and 1 <= int(category_choice) <= len(variables) + 1:
- category_choice = int(category_choice)
- # Initialize output data dictionary
- output_data = {}
- if category_choice == len(variables) + 1:
- # Select all categories
- selected_categories = list(variables.keys())
- else:
- # Select single category
- category_name = list(variables.keys())[category_choice - 1]
- selected_categories = [category_name]
- # Iterate over selected categories
- for category_name in selected_categories:
- # Display variables submenu for selected category
- print(f"\n{category_name} variables:\n")
- category_variables = variables[category_name]
- category_output = {}
- for num, var in sorted(category_variables.items()):
- value = os.environ.get(var)
- category_output[var] = value
- print(f"{num:02}. {var}: {value}")
- output_data[category_name] = category_output
- # Save environment output to text file
- save_environment_output(output_data)
- print("\nEnvironment output saved to 'environment_output.txt'.")
- else:
- print("\nInvalid category choice!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement