Click here to Skip to main content
15,885,767 members
Articles / Desktop Programming / Windows Forms
Article

Running a ClickOnce Application from Another Program

Rate me:
Please Sign up or sign in to vote.
2.94/5 (7 votes)
29 Apr 2008CPOL2 min read 72.2K   1.3K   25   16
A bootstrap loader to execute a ClickOnce application - written in C#

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:

plain
ExecuteClickOnceApp FHCRC\BuildIDWorklist <arguments >

ExecuteClickOnceApp will build a command line to the shortcut, along the lines of:

plain
<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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Gaby Mora G3-May-13 14:35
Gaby Mora G3-May-13 14:35 
GeneralMy vote of 1 Pin
Alex Cherkasov26-Sep-12 15:12
Alex Cherkasov26-Sep-12 15:12 
GeneralMy vote of 2 Pin
ido.ran3-Mar-12 10:21
ido.ran3-Mar-12 10:21 
GeneralMy vote of 4 Pin
richardza3-Mar-12 4:49
richardza3-Mar-12 4:49 
GeneralShellExecute [modified] Pin
Sabrina Hope22-Mar-10 4:42
Sabrina Hope22-Mar-10 4:42 
GeneralStart the .application click once file Pin
Adam Stechschulte19-Feb-10 5:13
Adam Stechschulte19-Feb-10 5:13 
GeneralAwesome! Pin
md5sum11-Feb-10 9:57
md5sum11-Feb-10 9:57 
GeneralURI formats are not supported [modified] Pin
José Luis Márquez10-Aug-09 12:50
José Luis Márquez10-Aug-09 12:50 
GeneralRe: URI formats are not supported Pin
José Luis Márquez10-Aug-09 13:12
José Luis Márquez10-Aug-09 13:12 
GeneralLanguage Pin
José Luis Márquez10-Aug-09 5:57
José Luis Márquez10-Aug-09 5:57 
GeneralRe: Language Pin
sandal_tolk27-Aug-09 20:55
sandal_tolk27-Aug-09 20:55 
AnswerRe: Language Pin
polleke_Gent28-Oct-09 0:06
polleke_Gent28-Oct-09 0:06 
GeneralRe: Language Pin
Sabrina Hope22-Mar-10 4:50
Sabrina Hope22-Mar-10 4:50 
GeneralCan't have Arguments Pin
dbrenth6-May-08 8:06
dbrenth6-May-08 8:06 
Your usage included [command parameters...], but in fact you cannot pass parameters into a click once manifest call as you could with an executable. I'm sure you noticed this since you never use args[1] and etc., but your article makes it look like this is possible.

But thanks for the article.

Brent
GeneralRe: Can't have Arguments Pin
dwrogers6-May-08 19:26
dwrogers6-May-08 19:26 
AnswerRe: Can't have Arguments [modified] Pin
Babba7216-Jul-09 21:45
Babba7216-Jul-09 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.