List installed programs and their versions
Here's a GO script that allows you to list installed programs and their versions:
package main
import (
"fmt"
"golang.org/x/sys/windows/registry"
)
func main() {
// Open the registry key for installed programs
regKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
if err != nil {
fmt.Println("Error opening registry key:", err)
return
}
defer regKey.Close()
// Get the list of subkeys (program entries)
subKeys, err := regKey.ReadSubKeyNames(-1)
if err != nil {
fmt.Println("Error reading subkeys:", err)
return
}
// Loop through each subkey (program entry)
for _, subKey := range subKeys {
programKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\`+subKey, registry.QUERY_VALUE)
if err != nil {
continue // Skip if unable to open the subkey
}
defer programKey.Close()
// Read the display name and version of the program
displayName, _, err := programKey.GetStringValue("DisplayName")
if err != nil {
continue // Skip if unable to read the display name
}
displayVersion, _, err := programKey.GetStringValue("DisplayVersion")
if err != nil {
continue // Skip if unable to read the display version
}
// Print program details
fmt.Printf("Name: %s\n", displayName)
fmt.Printf("Version: %s\n", displayVersion)
fmt.Println("----------------------------------------------")
}
}
In this script:
- We open the registry key where Windows stores information about installed programs (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall).
- We iterate through each subkey (which represents a program entry) within the registry key.
- For each program entry, we extract the display name, display version, and installation date from the registry values.
- We print out the program details including name and version.