Advertisement
Python253

win_env_var_explorer

Apr 19th, 2024
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.06 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: win_env_var_explorer.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script allows users to explore and display Windows environment variables grouped by categories.
  9. Users can navigate through a menu to select a category of environment variables and then choose a specific variable
  10. within that category to display its current value.
  11. The script provides a user-friendly interface for interacting with
  12. environment variables, making it easier for users to manage and understand their Windows environment configuration.
  13.  
  14. Requirements:
  15. - Python 3
  16. - Windows operating system
  17.  
  18. Usage:
  19. - Run the script using Python 3 in a Windows environment.
  20.  
  21. Additional Notes:
  22. - Ensure that Python 3 is installed on your system.
  23. - This script provides read-only access to environment variables and does not modify them.
  24. """
  25.  
  26. import os
  27.  
  28. # Dictionary of environment variables by category
  29. variables = {
  30.     "System Information": {
  31.         1: "ALLUSERSPROFILE",
  32.         2: "COMPUTERNAME",
  33.         3: "NUMBER_OF_PROCESSORS",
  34.         4: "OS",
  35.         5: "PROCESSOR_ARCHITECTURE",
  36.         6: "SYSTEMDRIVE",
  37.         7: "SYSTEMROOT",
  38.         8: "WINDIR"
  39.     },
  40.     "User Information": {
  41.         1: "APPDATA",
  42.         2: "HOMEDRIVE",
  43.         3: "HOMEPATH",
  44.         4: "LOCALAPPDATA",
  45.         5: "USERDOMAIN",
  46.         6: "USERNAME",
  47.         7: "USERPROFILE"
  48.     },
  49.     "File Paths": {
  50.         1: "CD",
  51.         2: "CommonProgramFiles",
  52.         3: "COMMONPROGRAMFILES(x86)",
  53.         4: "ProgramData",
  54.         5: "ProgramFiles",
  55.         6: "ProgramFiles(x86)",
  56.         7: "ProgramW6432",
  57.         8: "PSModulePath",
  58.         9: "Public",
  59.         10: "TEMP",
  60.         11: "TMP"
  61.     },
  62.     "Network": {
  63.         1: "ClientName",
  64.         2: "LOGONSERVER",
  65.         3: "HOMESHARE",
  66.         4: "OneDrive",
  67.         5: "OneDriveCommercial",
  68.         6: "OneDriveConsumer",
  69.         7: "UserDnsDomain",
  70.         8: "%SessionName%"
  71.     },
  72.     "Command Interpreter": {
  73.         1: "COMSPEC",
  74.         2: "CMDEXTVERSION",
  75.         3: "CMDCMDLINE",
  76.         4: "PROMPT"
  77.     },
  78.     "Date and Time": {
  79.         1: "DATE",
  80.         2: "TIME"
  81.     },
  82.     "Miscellaneous": {
  83.         1: "ERRORLEVEL",
  84.         2: "PATHEXT",
  85.         3: "RANDOM"
  86.     }
  87. }
  88.  
  89. # Main loop
  90. while True:
  91.     # Display categories menu
  92.     print("\nChoose a category of environment variables (type '0' to exit):\n")
  93.     for num, category in enumerate(variables.keys(), 1):
  94.         print(f"{num:02}. {category}")
  95.  
  96.     # Get user input for category choice
  97.     category_choice = input("\nEnter the number of the category you want to explore: ")
  98.  
  99.     # Exit if category choice is '0'
  100.     if category_choice == '0':
  101.         print("\nExiting...\tGoodBye!\n")
  102.         break
  103.  
  104.     # Validate category choice
  105.     if category_choice.isdigit() and 1 <= int(category_choice) <= len(variables):
  106.         category_choice = int(category_choice)
  107.         category_name = list(variables.keys())[category_choice - 1]
  108.  
  109.         # Display variables submenu for selected category
  110.         print(f"\n{category_name} variables:\n")
  111.         category_variables = variables[category_name]
  112.         for num, var in sorted(category_variables.items()):
  113.             print(f"{num:02}. {var}")
  114.  
  115.         # Get user input for variable choice
  116.         variable_choice = input("\nEnter the number of the variable you want to display (or '0' to go back): ")
  117.  
  118.         # Exit submenu if variable choice is '0'
  119.         if variable_choice == '0':
  120.             continue
  121.  
  122.         # Validate variable choice
  123.         if variable_choice.isdigit() and int(variable_choice) in category_variables:
  124.             selected_variable = category_variables[int(variable_choice)]
  125.             value = os.environ.get(selected_variable)
  126.             if value:
  127.                 print(f"\n\nThe value of {selected_variable} is: {value}\n\n")
  128.             else:
  129.                 print(f"\n{selected_variable} is not set.\n")
  130.         else:
  131.             print("\nInvalid choice!\n")
  132.     else:
  133.         print("\nInvalid category choice!\n")
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement