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_explorer.py
- # Version: 1.0.0
- # 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.
- 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.
- """
- 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"
- }
- }
- # 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}")
- # 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):
- category_choice = int(category_choice)
- category_name = list(variables.keys())[category_choice - 1]
- # Display variables submenu for selected category
- print(f"\n{category_name} variables:\n")
- category_variables = variables[category_name]
- for num, var in sorted(category_variables.items()):
- print(f"{num:02}. {var}")
- # Get user input for variable choice
- variable_choice = input("\nEnter the number of the variable you want to display (or '0' to go back): ")
- # Exit submenu if variable choice is '0'
- if variable_choice == '0':
- continue
- # Validate variable choice
- if variable_choice.isdigit() and int(variable_choice) in category_variables:
- selected_variable = category_variables[int(variable_choice)]
- value = os.environ.get(selected_variable)
- if value:
- print(f"\n\nThe value of {selected_variable} is: {value}\n\n")
- else:
- print(f"\n{selected_variable} is not set.\n")
- else:
- print("\nInvalid choice!\n")
- else:
- print("\nInvalid category choice!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement