2

I am currently trying to get a list of all installed applications and would like to build a feature that can launch those.

I'm using these PowerShell commands:

gci HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation

gci HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation

in conjunction with ConvertTo-Json in order to get a good stdout I can work with. Now, this only gives me the InstallPath without any executables.

Is there any easy way to get the main executable of the applications i nthe list?

Expected Result (Name of the key does not matter):

    // ...
    {
        "DisplayName":  "Microsoft Edge",
        "InstallLocation":  "C:\\Program Files (x86)\\Microsoft\\Edge\\Application",
        "LaunchApplication": "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\msedge.exe",
    },
    {
        "DisplayName":  "Audacity 2.4.2",
        "InstallLocation":  "C:\\Program Files (x86)\\Audacity\\",
        "LaunchApplication": "C:\\Program Files (x86)\\Audacity\\audacity.exe"
    },
    // ...
8
  • Why would you need to pipe to ConvertTo-Json? Also, what do you mean by how the start menu does? What should be the expected result? Commented Apr 15, 2022 at 21:45
  • @AbrahamZinala I'm grabbing the list via exec and am outputting the list in an electron application, which is why I need it in json
    – Tom M
    Commented Apr 15, 2022 at 21:50
  • @AbrahamZinala I added an expected Result
    – Tom M
    Commented Apr 15, 2022 at 21:50
  • @AbrahamZinala I also edited the question to clarify
    – Tom M
    Commented Apr 15, 2022 at 21:56
  • 1
    Unfortunately there is no standard way of getting executable paths of installed applications. You have to use heuristic approach by looking for start menu shortcuts (*.lnk) that point to executable(s) within InstallLocation.
    – zett42
    Commented Apr 15, 2022 at 22:25

1 Answer 1

6

Like others have pointed out in the comments, there isn't a conventional way of getting the executable paths of certain programs.

To answer your indirect question of building an app launch method, we can make use of a few things. Fortunately for us, PowerShell has a Get-StartApps cmdlet that produces an output of the current users installed apps:


Name                                                 AppID
----                                                 -----
3D Viewer                                            Microsoft.Microsoft3DViewer_8wekyb3d8bbwe!Microsoft.Microsoft3DViewer
AdGuard                                              AdGuard
Adobe Acrobat DC                                     {6D809377-6AF0-444B-8957-A3773F02200E}\Adobe\Acrobat DC\Acrobat\Acrobat.exe
Battle.net                                           {7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\Battle.net\Battle.net Launcher.exe
Blend for Visual Studio 2022                         Blend.d58ce8bb
Calculator                                           Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
Calendar                                             microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.calendar

There are 2 properties that are displayed:

  • Name
  • AppID.

This becomes important due to the AppID being the value needed for shell: to execute/launch the program. Given the above output of Get-StartApps, you can launch "Adobe Acrobat DC" by passing the AppID to shell:\AppsFolder\"AppID".

Start-Process shell:AppsFolder\"{6D809377-6AF0-444B-8957-A3773F02200E}\Adobe\Acrobat DC\Acrobat\Acrobat.exe"

Using @zett42's approach, we can query your start menu, along with the system start menu folder paths for .lnk's retrieving its target path using the WScript COM object:

$paths = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs","$env:APPDATA\Microsoft\Windows\Start Menu"
Get-ChildItem -Path $paths -Filter "*.lnk" -File -Recurse | 
    ForEach-Object -Begin {
        $WScriptShell = New-Object -ComObject "WScript.Shell"
    } -Process {
        [PSCustomObject]@{
            Name = $_.BaseName
            Path = $WScriptShell.CreateShortcut($_.FullName).TargetPath
        }
    } -End {
        [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($WScriptShell) #release COM object
    }

which will output:

Name                         Path
----                         ----
Adobe Acrobat DC             C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe
Blend for Visual Studio 2022 C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Blend.exe
Firefox                      C:\Program Files\Mozilla Firefox\firefox.exe
Google Chrome                C:\Program Files\Google\Chrome\Application\chrome.exe
Microsoft Edge               C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
TechPowerUp GPU-Z            C:\Program Files (x86)\GPU-Z\GPU-Z.exe

Not entirely sure this is what you're after, but it may be of help to others.

1
  • 1
    I get the output I require by appending | ConvertTo-Json . Thank you very much, good sir
    – Tom M
    Commented Apr 16, 2022 at 2:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.