Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching a ClickOnce application from another ClickOnce application

Tags:

c#

clickonce

My goal is to actually achieve launching my ClickOnce application in one click (or two I guess). 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. This involves downloading the EXE file (one click), running it (two clicks), then after prerequisites are installed, clicking again to run the ClickOnce application.

I'm trying to reduce this process to one or two clicks: - Click a link on my website to the ClickOnce .application file. - Click again to run it.

I have made ANOTHER ClickOnce application, which includes a setup.exe. It checks if the prerequisites are installed, and if they are it runs the other ClickOnce application automatically. If not, it runs the included setup.exe and then runs the other ClickOnce application.

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.

I'm trying to use the following to start the ClickOnce application from inside my C# code:

Process.Start(ApplicationURL);

I just want this to automatically launch the application at 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).

like image 999
Jschiff Avatar asked Jan 05 '12 15:01

Jschiff


3 Answers

There are at least 2 other methods for launching ClickOnce applications.

One simple method is Process.Start("PresentationHost.exe", "-launchApplication " + ApplicationURL); as documented by Microsoft here.

A more sophisticated method is calling ShellExecuteEx() Win32 API with code like this:

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. This method will query registry and run "rundll32.exe dfshim.dll,ShOpenVerbApplication" (or anything else that is configured under HKEY_CLASSES_ROOT\Application.Manifest).

like image 83
DavisNT Avatar answered Nov 14 '22 00:11

DavisNT


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. You can also launch the ClickOnce application the same way Windows Explorer launches it, using dfshim.dll.

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.

  • Another Stack Overflow question mentions using a custom .exe to install the .NET Framework and then launch a ClickOnce application via ShOpenVerbApplication.
  • 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.

Update

As the other Stack Overflow question mentions, you can also use dfshim.dll's LaunchApplication command, which is documented on Microsoft's site. However, that command is not available in some older versions of the .NET Framework.

like image 28
Tommy Vernieri Avatar answered Nov 14 '22 01:11

Tommy Vernieri


Have a look at the Microsoft walkthrough for installing manually via InPlaceHostingManager. You have the ability to customize programmatically.

like image 1
dgp Avatar answered Nov 14 '22 01:11

dgp