2

I have a problem, and I couldn't find any solution to it. I use this package to get all the application installed on a computer: https://github.com/aybe/Windows-API-Code-Pack-1.1. I use this in order to get the file path where the application is installed.

So I use this code to iterate over it:

// Virtual application folder to get all the application
Guid FOLDERID_AppsFolder = new Guid("{1e87508d-89c2-42f0-8a7e-645a0f50ca58}");
ShellObject appsFolder = (ShellObject)KnownFolderHelper.FromKnownFolderId(FOLDERID_AppsFolder);

// Iterate over all the application installed
foreach (ShellObject app in (IKnownFolder)appsFolder)
{
    // Get the friendly app name
    string name = app.Name;
    // Get the parsing path, i.e something like that: 308046B0AF4A39CB
    string parsingPath = app.Properties.System.ParsingPath.Value;

    // ... Need to get the file path, i.e something like that: C:\Program Files\MyApp\myApp.exe
}

I try to find what is this value, I assume maybe it's a PIDL, but unfortunately, all the commands that I have try, return an error about Windows that tries to write into a protected memory area. So maybe it's not a PIDL, or not directly linked.

Thomas
  • 104
  • 1
  • 6
  • Take a step back - **why** are you doing this? – mjwills Jul 16 '20 at 12:25
  • Looks like library you are using is really getting installed software from the registry. You may be able to use code at following posting : https://stackoverflow.com/questions/24909108/get-installed-software-list-using-c-sharp – jdweng Jul 16 '20 at 12:59
  • "The file path where the application is installed" concept does not exist. Two interesting properties are "System.Link.TargetParsingPath" (you can use the directory for that path) for non UWP apps and "System.AppUserModel.PackageInstallPath" for UWP apps. – Simon Mourier Jul 16 '20 at 12:59
  • I do this for a program that can launch some application installed on the computer and put them in a tab (like a web browser). – Thomas Jul 16 '20 at 13:00

1 Answers1

1

I have now my answer in the comments of my post thanks to Simon Mourier.

By using this property, you can find the real path: System.Link.TargetParsingPath.Value. However, I can't find the other property for the UWP app described in the comments.

Here is the completed code:

// GUID taken from https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid
// Virtual application folder to get all the application
Guid FOLDERID_AppsFolder = new Guid("{1e87508d-89c2-42f0-8a7e-645a0f50ca58}");
ShellObject appsFolder = (ShellObject)KnownFolderHelper.FromKnownFolderId(FOLDERID_AppsFolder);

// Iterate over all the application installed
foreach (ShellObject app in (IKnownFolder)appsFolder)
{
    // Get the friendly app name
    string name = app.Name;
    // Get the parsing path, i.e something like that: something like that: C:\Program Files\MyApp\myApp.exe
    string applicationPath = app.Properties.System.Link.TargetParsingPath.Value;

    // Make what you want here...
}

As described in the comments, this path can be anything, you can sometimes find .url files, .txt files, or complete URL. So be aware of the path.

Thanks for all the people who help me!

Thomas
  • 104
  • 1
  • 6