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).
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).
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.
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.
Have a look at the Microsoft walkthrough for installing manually via InPlaceHostingManager. You have the ability to customize programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With