如何发现应用程序的主要可执行文件 [英] How to discover the main executable file of an application
问题描述
我正在以无人值守的方式以编程方式安装应用程序(没什么特别的,只是传递参数/VERYSILENT/SUPPRESSMSGBOXES/NORESTART"如果是 exe,或者msiexec/qn/i ALLUSERS=1"而是 msi 文件).
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?
推荐答案
我找到了合适的方法,希望可以帮到大家.
I've found a suitable way, I hope this could help anyone else.
Windows 10 中有一个特殊的隐藏外壳对象,它列出了所有以这种方式打开的应用程序(UWP 和常规):
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
- 放入 Shell:AppsFolder 并执行它.
然后就是以编程方式获取列表并检查安装后发生了什么变化的问题.
Then it's a question of getting the list there programatically and checking what have changed after installation.
这是通过这种方式实现的(需要 this nuget 包):
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 是应用程序的名称,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
感谢此答案的解决方案.
那么现在是存储当前列表的问题,安装新的应用程序,然后检查该列表上的更改.同样如答案所暗示的那样;您可以监听该 shellobject 上的更改,以便在更改生效时收到通知,如下所示:
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();
这篇关于如何发现应用程序的主要可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!