How to discover the main executable file of an application

好久不见. 提交于 2020-04-18 12:35:44

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/60440044/how-to-discover-the-main-executable-file-of-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!