Get a file path from a parsingPath of a ShellObject

Viewed 534

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.

1 Answers

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://docs.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!

Related