Get all installed software and their corresponding license information on Windows OS with C#

  • 1 year ago
Comment

1 / 1

To get all installed software and their corresponding license information on a Windows OS with C#, you can use the Microsoft.Win32 namespace to access the Windows Registry. Here's an example of how to do it:

csharp
using System;
using Microsoft.Win32;

class Program
{
static void Main(string[] args)
{
// Open the key for the installed software in the registry
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");

// Loop through all the subkeys (installed software)
foreach (string subKeyName in key.GetSubKeyNames())
{
// Open the subkey
RegistryKey subkey = key.OpenSubKey(subKeyName);

// Get the display name and license information (if available)
string displayName = subkey.GetValue("DisplayName") as string;
string licenseInfo = subkey.GetValue("LicenseInfo") as string;

// Print the results
Console.WriteLine("{0}: {1}", displayName, licenseInfo);

// Close the subkey
subkey.Close();
}

// Close the key for the installed software
key.Close();
}
}

In this example, we first open the registry key for the installed software using Registry.LocalMachine.OpenSubKey(). We then loop through all the subkeys (installed software) using key.GetSubKeyNames(), and open each subkey using key.OpenSubKey(). We then retrieve the display name and license information (if available) using subkey.GetValue(). Finally, we print the results to the console and close the subkey using subkey.Close().

Note that this code only retrieves the display name and license information for installed software that has been registered with the Windows Installer service. Some installed software may not be listed in this location in the registry, and some may not include license information. Additionally, the license information may be encoded or encrypted in some cases, and may require additional parsing or decryption.