Advertisement
Python253

installed_.net_frameworks

Apr 6th, 2024
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: installed_.net_frameworks.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script retrieves version information about all installed .NET Framework versions on a Windows system.
  9. """
  10.  
  11. import winreg
  12.  
  13. def get_dotnet_frameworks():
  14.     """
  15.    Get installed .NET Framework versions.
  16.  
  17.    Returns:
  18.        list: A list of installed .NET Framework versions.
  19.    """
  20.     dotnet_versions = []
  21.     dotnet_release_keys = [
  22.         (winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\NET Framework Setup\NDP"),
  23.         (winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP")
  24.     ]
  25.  
  26.     for hive, subkey in dotnet_release_keys:
  27.         with winreg.OpenKey(hive, subkey, 0, winreg.KEY_READ) as key:
  28.             subkey_names_count, _, _ = winreg.QueryInfoKey(key)
  29.             for i in range(subkey_names_count):
  30.                 subkey_name = winreg.EnumKey(key, i)
  31.                 if subkey_name.startswith("v") and subkey_name not in dotnet_versions:
  32.                     dotnet_versions.append(subkey_name)
  33.  
  34.     return dotnet_versions
  35.  
  36. def main():
  37.     """
  38.    Main function to retrieve installed .NET Framework versions and print them.
  39.    """
  40.     dotnet_versions = get_dotnet_frameworks()
  41.     if dotnet_versions:
  42.         print("Installed .NET Framework versions:")
  43.         for version in dotnet_versions:
  44.             print(f"- {version}")
  45.     else:
  46.         print("No .NET Frameworks found.")
  47.  
  48. if __name__ == "__main__":
  49.     main()
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement