Search code examples
c#windowswinapiwindows-installer

How to discover the main executable file of an application


I am installing applications programatically in an unattended fashion ( nothing special, just passing the paramters "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART" if exe, or "msiexec /qn /i ALLUSERS=1" while is an msi file ).

The problem is after installation suceded I want to open the application I've just installed. Then I am looking for a way to discover the main executable file of an application I've just installed.

I've tried monitoring harddisk and also checking on registry but I hasn't found anything robust and universal.

How can I achieve that?


Solution

  • I've found a suitable way, I hope this could help anyone else.

    There's an special hidden shell object in Windows 10 who list all the applications (UWP and regular) that gets open in this way:

    • Win + R
    • Put Shell:AppsFolder and execute it.

    Then it's a question of getting the list there programatically and checking what have changed after installation.

    This is achieved in this way (It's needed this nuget package):

    var appsFolderId = new Guid("{1e87508d-89c2-42f0-8a7e-645a0f50ca58}");
    IKnownFolder appsFolder = KnownFolderHelper.FromKnownFolderId(appsFolderId);
    foreach (var app in appsFolder)
    {
      Console.WriteLine($"{app.Name} {app.ParsingName}");
    }
    

    app.Name is the name of the app, and app.ParsingName is the name that can be used to open the application using this:

    System.Diagnostics.Process.Start("explorer.exe", @" shell:appsFolder\" + app.ParsingName);
    

    If needed, you can get the icon of the app through this property:

    app.Thumbnail.ExtraLargeBitmapSource
    

    Credits to this answer for the solution.

    Then now is a question of storing the current list, install the new app and check changes on that list after. Also as the answer suggests; you can listen for changes on that shellobject to get notified while the change is effective, with this:

    ShellObjectWatcher watcher = new ShellObjectWatcher(appsFolder, false);
    watcher.AllEvents += <Your_events_handler>;
    watcher.Start();