简体   繁体   English

如何发现应用程序的主要可执行文件

[英]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 ).我正在以无人值守的方式以编程方式安装应用程序(没什么特别的,只是传递参数“/VERYSILENT /SUPPRESSMSGBOXES /NORESTART”如果是 exe,或者“msiexec /qn /i ALLUSERS=1”而是 msi 文件)。

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?我怎样才能做到这一点?

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: Windows 10 中有一个特殊的隐藏外壳对象,它列出了所有以这种方式打开的应用程序(UWP 和常规):

  • Win + R赢+R
  • Put Shell:AppsFolder and execute it.放入 Shell:AppsFolder 并执行它。

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):这是通过这种方式实现的(需要这个nuget 包):

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: app.Name 是应用程序的名称,app.ParsingName 是可用于打开应用程序的名称:

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:您可以侦听该 shellobject 上的更改以在更改生效时获得通知,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM