Click here to Skip to main content
14,983,064 members
Articles / Desktop Programming / Windows Forms
Posted 29 Apr 2008


25 bookmarked

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
A bootstrap loader to execute a ClickOnce application - written in C#


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.


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.


  • 29-04-2008: Initial upload


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


About the Author

Web Developer
United States United States
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Gaby Mora G3-May-13 14:35
MemberGaby Mora G3-May-13 14:35 
GeneralMy vote of 1 Pin
Alex Cherkasov26-Sep-12 15:12
MemberAlex Cherkasov26-Sep-12 15:12 
GeneralMy vote of 2 Pin
ido.ran3-Mar-12 10:21
Memberido.ran3-Mar-12 10:21 
GeneralMy vote of 4 Pin
richardza3-Mar-12 4:49
Memberrichardza3-Mar-12 4:49 
GeneralShellExecute [modified] Pin
Sabrina Hope22-Mar-10 4:42
MemberSabrina Hope22-Mar-10 4:42 
GeneralStart the .application click once file Pin
Adam Stechschulte19-Feb-10 5:13
MemberAdam Stechschulte19-Feb-10 5:13 
GeneralAwesome! Pin
md5sum11-Feb-10 9:57
Membermd5sum11-Feb-10 9:57 
GeneralURI formats are not supported [modified] Pin
José Luis Márquez10-Aug-09 12:50
MemberJosé Luis Márquez10-Aug-09 12:50 
GeneralRe: URI formats are not supported Pin
José Luis Márquez10-Aug-09 13:12
MemberJosé Luis Márquez10-Aug-09 13:12 
GeneralLanguage Pin
José Luis Márquez10-Aug-09 5:57
MemberJosé Luis Márquez10-Aug-09 5:57 
GeneralRe: Language Pin
sandal_tolk27-Aug-09 20:55
Membersandal_tolk27-Aug-09 20:55 
AnswerRe: Language Pin
polleke_Gent28-Oct-09 0:06
Memberpolleke_Gent28-Oct-09 0:06 
GeneralRe: Language Pin
Sabrina Hope22-Mar-10 4:50
MemberSabrina Hope22-Mar-10 4:50 
GeneralCan't have Arguments Pin
dbrenth6-May-08 8:06
Memberdbrenth6-May-08 8:06 
GeneralRe: Can't have Arguments Pin
dwrogers6-May-08 19:26
Memberdwrogers6-May-08 19:26 
AnswerRe: Can't have Arguments [modified] Pin
Babba7216-Jul-09 21:45
MemberBabba7216-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.