Mohit Deshpande
Mohit Deshpande

Reputation: 55217

Get paths of all applications in the registry

string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryKey))
        {
            (from a in key.GetSubKeyNames()
             let r = key.OpenSubKey(a)
             select new
             {
                 Application = r.GetValue("DisplayName")
             }).ToList().FindAll(c => c.Application != null).ForEach(c => Debug.WriteLine(c.Application));

This snippet displays all the names of the application in the registry. I need the paths to the exe files that execute the application and I need to know how to run them using Process.Start();

Upvotes: 1

Views: 2345

Answers (2)

dlamblin
dlamblin

Reputation: 45321

In case you're trying to get all installed applications -- your title is the only question and clearly you ask about the registry -- you may also consider querying the Win32_product class from the WMI Service, an example with scripting is documented in: https://learn.microsoft.com/en-us/previous-versions/tn-archive/ee156540(v=technet.10)

Both the registry folder above and the WMI service have this caveat though:

The WMI Win32_Product class enables you to enumerate the software installed on a computer, provided the software was installed by using the Windows Installer

In case the URL changes I'll put the entire script from the document below:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
 & "Version"
For Each objSoftware in colSoftware
 objTextFile.WriteLine objSoftware.Caption & vbtab & _
 objSoftware.Description & vbtab & _
 objSoftware.IdentifyingNumber & vbtab & _
 objSoftware.InstallLocation & vbtab & _
 objSoftware.InstallState & vbtab & _
 objSoftware.Name & vbtab & _
 objSoftware.PackageCache & vbtab & _
 objSoftware.SKUNumber & vbtab & _
 objSoftware.Vendor & vbtab & _
 objSoftware.Version
Next
objTextFile.Close

You'll also find that PowerShell has some nicer ways to get data from wmi:

get-wmiobject Win32_Product |
 Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

But again, I'm finding that all these methods only give a small subset of what's installed, or what's shown by "Add or remove programs" in the Windows settings/control-panel. I further wonder how a more complete list can be built. Though you indicated you only wanted what was under that registry key, which is completely reflected by the above.

Upvotes: 0

Jesse Weigert
Jesse Weigert

Reputation: 4854

There isn't really a definitive source for this anywhere in Windows. The closest you'll get is by enumerating the start menu. View this post for how to do that: Programmatically access All Users Start Menu

Basically, you need to call the SHGetSpecialFolderPath API to retrieve the location of the start menu and then enumerate all of the shortcuts in that path.

This stackoverflow question talks about how to extract the icon from a shortcut; you can use the same method to extract the working path and executable which you would need to launch the application: Extract Icon from Windows .lnk (shortcut) file

Upvotes: 1

Related Questions