简体   繁体   English

从另一个 ClickOnce 应用程序启动 ClickOnce 应用程序

[英]Launching a ClickOnce application from another ClickOnce application

My goal is to actually achieve launching my ClickOnce application in one click (or two I guess).我的目标是真正实现一键启动我的 ClickOnce 应用程序(或者我猜是两次)。 The application has some prerequisites which need to be installed.该应用程序有一些需要安装的先决条件。 The normal way of ensuring they are installed that Microsoft provides involves having the user decide whether he has the prerequisites or not and downloading and installing a "setup.exe" which installs them and runs the ClickOnce application. Microsoft 提供的确保安装它们的正常方法包括让用户决定他是否具有先决条件,然后下载和安装“setup.exe”,该“setup.exe”会安装它们并运行 ClickOnce 应用程序。 This involves downloading the EXE file (one click), running it (two clicks), then after prerequisites are installed, clicking again to run the ClickOnce application.这包括下载 EXE 文件(单击一次)、运行它(单击两次),然后在安装了先决条件后,再次单击以运行 ClickOnce 应用程序。

I'm trying to reduce this process to one or two clicks: - Click a link on my website to the ClickOnce .application file.我试图将这个过程减少到一两次点击: - 点击我网站上指向 ClickOnce .application文件的链接。 - Click again to run it. - 再次单击以运行它。

I have made ANOTHER ClickOnce application, which includes a setup.exe.我制作了另一个 ClickOnce 应用程序,其中包括一个 setup.exe。 It checks if the prerequisites are installed, and if they are it runs the other ClickOnce application automatically.它检查是否安装了先决条件,如果已安装,它会自动运行其他 ClickOnce 应用程序。 If not, it runs the included setup.exe and then runs the other ClickOnce application.如果没有,它会运行包含的 setup.exe,然后运行其他 ClickOnce 应用程序。

My problem is that when I try to run the other ClickOnce application from this one, it simply opens my web browser and downloads the .application file without running it.我的问题是,当我尝试从该应用程序运行另一个 ClickOnce 应用程序时,它只是打开我的网络浏览器并下载 .application 文件而不运行它。

I'm trying to use the following to start the ClickOnce application from inside my C# code:我正在尝试使用以下内容从我的 C# 代码中启动 ClickOnce 应用程序:

Process.Start(ApplicationURL);

I just want this to automatically launch the application at ApplicationURL.我只想让它在 ApplicationURL 自动启动应用程序。 Is there a way to skip the browser involvement that I'm seeing?有没有办法跳过我看到的浏览器参与?

(My question is very similar to Stack Overflow question Run a ClickOnce application from a webpage without user action ). (我的问题非常类似于 Stack Overflow 问题Run a ClickOnce application from a pages without user action )。

As pointed out in the comments, you can start the iexplore.exe process to launch a ClickOnce application without any dependency on the default browser.正如评论中所指出的,您可以启动iexplore.exe进程来启动 ClickOnce 应用程序,而不依赖于默认浏览器。 You can also launch the ClickOnce application the same way Windows Explorer launches it, using dfshim.dll .您还可以使用dfshim.dll启动 ClickOnce 应用程序,就像 Windows 资源管理器启动它一样。

Process.Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + ApplicationURL);

There are a few other articles online that discuss using this strategy, but I did not find any official documenation of dfshim.dll,ShOpenVerbApplication.网上还有其他几篇文章讨论了使用这种策略,但是我没有找到 dfshim.dll,ShOpenVerbApplication 的任何官方文档。

  • Another Stack Overflow question mentions using a custom .exe to install the .NET Framework and then launch a ClickOnce application via ShOpenVerbApplication. 另一个 Stack Overflow 问题提到使用自定义 .exe 安装 .NET Framework,然后通过 ShOpenVerbApplication 启动 ClickOnce 应用程序。
  • Scott Hanselman discusses ShOpenVerbApplication as the default file mapping for files with the application/x-ms-application MIME type in a post about Firefox and ClickOnce. Scott Hanselman 在一篇关于 Firefox 和 ClickOnce 的文章中讨论了 ShOpenVerbApplication作为具有 application/x-ms-application MIME 类型的文件的默认文件映射。

Update更新

As the other Stack Overflow question mentions, you can also use dfshim.dll 's LaunchApplication command, which is documented on Microsoft's site .正如另一个 Stack Overflow 问题所提到的,您还可以使用dfshim.dllLaunchApplication命令,该命令记录在 Microsoft 的网站上 However, that command is not available in some older versions of the .NET Framework.但是,该命令在某些旧版本的 .NET Framework 中不可用。

There are at least 2 other methods for launching ClickOnce applications.至少有 2 种其他方法可以启动 ClickOnce 应用程序。

One simple method is Process.Start("PresentationHost.exe", "-launchApplication " + ApplicationURL);一种简单的方法是Process.Start("PresentationHost.exe", "-launchApplication " + ApplicationURL); as documented by Microsoft here .正如微软在此处记录的那样。

A more sophisticated method is calling ShellExecuteEx() Win32 API with code like this:更复杂的方法是调用ShellExecuteEx() Win32 API,代码如下:

SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpFile = ApplicationURL;
info.nShow = SW_SHOWNORMAL;
info.fMask = SEE_MASK_CLASSNAME;
info.lpClass = "Application.Manifest";
ShellExecuteEx(ref info);

Required Win32 API import and structure definitions can be found here .可以在此处找到所需的 Win32 API 导入和结构定义。 This method will query registry and run "rundll32.exe dfshim.dll,ShOpenVerbApplication" (or anything else that is configured under HKEY_CLASSES_ROOT\Application.Manifest ).此方法将查询注册表并运行“rundll32.exe dfshim.dll,ShOpenVerbApplication”(或在HKEY_CLASSES_ROOT\Application.Manifest下配置的任何其他内容)。

Have a look at the Microsoft walkthrough for installing manually via InPlaceHostingManager .查看通过InPlaceHostingManager手动安装的Microsoft 演练 You have the ability to customize programmatically.您可以以编程方式进行自定义。

Following are the ways to launch clickonce.application以下是启动 clickonce.application 的方法

Approach 1: Launch from URL方法 1:从 URL 启动

Method 1:方法一:

string app = "http://domain.xyz/ClickOnce.application";
Process.Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + app);

Method 2:方法二:

string app = "http://domain.xyz/ClickOnce.application";
Process.Start("IExplore.exe", app);

Approach 2: Directly launch ClickOnce.application from .application file方法 2:直接从 .application 文件启动 ClickOnce.application

string app = "file://C:/ClickOnce.application";
Process.Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + app);

And another option is using Launcher::LaunchUriAsync with LauncherOptions.ContentType = "application/x-ms-application".另一种选择是使用Launcher::LaunchUriAsync和 LauncherOptions.ContentType = "application/x-ms-application"。 This is known a "uri direct invoke"这称为“uri 直接调用”

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

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