Introduction
There are times when it is desirable to run a ClickOnce application from another program. While there are several articles that address this to some degree, I have not found any which seem adequate.
Some caveats: I'm only concerned with offline-capable ClickOnce applications. Also, this code doesn't help you get a return code from a ClickOnce application. Moreover, this technique will only work if there is a single instance of the ClickOnce application running at any time.
Background
A good read in this area is "Smart Client Deployment with ClickOnce" by Brian Noyes.
Using the Code
So, why bother? Well, imagine (if you will) a third party application with a scripting language which includes the ability to execute a program. Further, imagine that you have multiple people (Windows users) using that application. How can you create a single script which will have the application execute a ClickOnce application?
A ClickOnce application will have a different location depending on the current user, so you need something which will do that redirection. My solution is to use the application described herein, ExecuteClickOnceApp
, which will execute a ClickOnce application given the company name and the application name. Note that this bootstrap application is distributed via a setup project. I can't use ClickOnce for the bootstrap program, but it is a mostly static program launcher, and allows the less generic and more changeable applications to be run as ClickOnce applications.
Back to the script – if for example, my company name is FHCRC, and my application is called BuildIDWorklist
, then I will script in the command:
ExecuteClickOnceApp FHCRC\BuildIDWorklist <arguments >
ExecuteClickOnceApp
will build a command line to the shortcut, along the lines of:
<USERPROFILE>\Start Menu\Programs\FHCRC\BuildIDWorklist.appref-ms
It will then start up a process with this command line and wait for the process to exit. That’s all folks!
Points of Interest
There were a couple of maddening things about this development process. First, when using Process.Start()
to initiate a ClickOnce application, using an application reference (as above), the returned process is not valid. So, you can't wait for it to complete, or check for a return code. Instead, you have to examine all running processes looking for your application.
The other big gotcha is that there does not appear to be a straightforward way to get at the exit code from the ClickOnce application. Even after you locate the process, the Framework refuses to divulge the exit code on the grounds that you didn't actually start the process in question.
History
- 29-04-2008: Initial upload