Click here to Skip to main content
15,884,686 members
Articles / Operating Systems / Windows

Launching a ClickOnce Application from Another ClickOnce Application

Rate me:
Please Sign up or sign in to vote.
2.40/5 (5 votes)
23 May 2006CPOL2 min read 99.5K   18   20
How to launch a ClickOnce application from another ClickOnce application

Introduction

ClickOnce applications do a great job of isolating applications from each other. This was done for two reasons, security and maintainability. Firstly, it allows for greater security since the .NET Framework manages security via code access policies. Secondly, it increases maintainability by preventing the problems with "DLL hell". But this does pose a problem when one wants to launch the application. While it is installed on the hard drive, the framework installs it in different locations for every user.

Microsoft solved this problem by creating a special type of shortcut, called an "application reference" that is used in the start menu when a ClickOnce application is installed locally. Great, now we can launch an application from the start menu, but what if we want to launch it from another application?

To answer this problem, I started where many of you are thinking. I will just use the URL to the .application manifest file on the server. Just do a System.Diagnostics.Process.Start on the URL and I am good to go. While this will work fine in an always connected scenario, it doesn't work if the application needs to run in offline mode.

For those applications, I suggest doing a little bit of thievery. Since the application reference (*.appref-ms) that is created in the start menu will launch the application (if it is installed) for any user on any computer (with the .NET Framework 2.0 installed), all we need to do is steal it out of the start menu and embed it in our launching application.

This technique is useful for applications that run in an online/offline mode. For online only application, I suggest using just the URL.

The Code

  1. Create the Client application
    1. Create a new Windows Application in VS.NET 2005
    2. Call it ClickOnceClient
    3. Publish it, with all the default settings
    4. Install it
  2. Find the application reference file from the start menu
    1. Using file explorer, navigate to C:\Documents and Settings\(user)\Start Menu\Programs\(company)
  3. Create the Launcher application
    1. Create a new Windows Application in VS.NET 2005
    2. Call it ClickOnceLauncher
    3. Add the application reference file for the client to the project
    4. Set its "Copy to Output Directory" property to "Copy always"
    5. Set its "Build Action" property to "Content"
    6. Add a button to the form
    7. In the click event of the button, add a Process.Start for the file you just copied in
    8. Publish it, with all the default settings
    9. Install it
    10. Run it

History

  • 2006/05/23 Created

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
Shawn is an Orlando FL based developer and president of the Orlando .NET Users Group (http://www.onetug.org). Currently he is doing intranet & smart client development at a local fortune 500 company and teaches at the Florida Institute of Technology. Shawn started his career at his family business in Port St. Lucie Florida while working on his undergraduate degree in Business Administration at the University of Central Florida and after a year off Shawn moved to Orlando to pursue a Masters degree in Management Information Systems at UCF. Before graduating Shawn worked as an intern at the company he currently works full time for. Currently Shawn is working on a second Masters degree in Computer Science at FIT. Besides his work, Shawn enjoys volunteering with local organizations.

Comments and Discussions

 
Generalrun at startup Pin
Diego.Veras4-Oct-08 4:26
Diego.Veras4-Oct-08 4:26 
GeneralRe: run at startup Pin
saw12345-Oct-08 23:26
saw12345-Oct-08 23:26 
AnswerIf you have 3.5 SP1, Process.Start({ClickOnce URL}) works fine in Offline mode Pin
hhawork18-Sep-08 8:16
hhawork18-Sep-08 8:16 
GeneralClick Once Launcher - Easy Method Pin
Member 472153615-Apr-08 0:46
Member 472153615-Apr-08 0:46 
GeneralRe: Click Once Launcher - Easy Method Pin
tsk2229-Apr-08 6:52
tsk2229-Apr-08 6:52 
GeneralClickOnce silent Pin
Eli Gazit16-Oct-07 2:17
Eli Gazit16-Oct-07 2:17 
GeneralRe: ClickOnce silent Pin
Eli Gazit30-Oct-07 21:53
Eli Gazit30-Oct-07 21:53 
Generalthere is a problem for this approach Pin
stevendonline10-Nov-06 8:11
stevendonline10-Nov-06 8:11 
GeneralRe: there is a problem for this approach Pin
DTMxxLLC30-Aug-07 16:28
DTMxxLLC30-Aug-07 16:28 
GeneralI like the idea Pin
_alank26-Sep-06 9:38
_alank26-Sep-06 9:38 
GeneralRe: I like the idea Pin
saw123427-Sep-06 23:27
saw123427-Sep-06 23:27 
No, by including the application reference file from the start menu the click once application opens without calling a browser. The trick is doing the Process.Start on the application reference (*.appref-ms) file not on the URL.

Shawn Weisfeld
President Orlando .NET Users Group
http://www.onetug.org

GeneralRe: I like the idea Pin
_alank28-Sep-06 1:47
_alank28-Sep-06 1:47 
Questionwhy launch this way ? Pin
BillWoodruff1-Jun-06 9:09
professionalBillWoodruff1-Jun-06 9:09 
AnswerRe: why launch this way ? Pin
saw12345-Jun-06 7:43
saw12345-Jun-06 7:43 
GeneralRe: why launch this way ? Pin
BillWoodruff5-Jun-06 8:16
professionalBillWoodruff5-Jun-06 8:16 
GeneralRe: why launch this way ? Pin
saw123412-Jun-06 1:49
saw123412-Jun-06 1:49 
GeneralRe: why launch this way ? Pin
travis_1121121430-Apr-07 22:52
travis_1121121430-Apr-07 22:52 
GeneralRe: why launch this way ? Pin
saw123430-Apr-07 23:17
saw123430-Apr-07 23:17 
GeneralRe: why launch this way ? Pin
travis_112112141-May-07 1:04
travis_112112141-May-07 1:04 
GeneralRe: why launch this way ? Pin
saw12341-May-07 15:49
saw12341-May-07 15:49 

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.