Click here to Skip to main content
11,704,107 members (55,465 online)
Click here to Skip to main content

Launching a ClickOnce Application from Another ClickOnce Application

, 23 May 2006 CPOL 75.4K 18
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

saw1234
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.

You may also be interested in...

Comments and Discussions

 
Generalrun at startup Pin
Diego.Veras4-Oct-08 4:26
memberDiego.Veras4-Oct-08 4:26 
GeneralRe: run at startup Pin
saw12345-Oct-08 23:26
membersaw12345-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
memberhhawork18-Sep-08 8:16 
GeneralClick Once Launcher - Easy Method Pin
Member 472153615-Apr-08 0:46
memberMember 472153615-Apr-08 0:46 
GeneralRe: Click Once Launcher - Easy Method Pin
tsk2229-Apr-08 6:52
membertsk2229-Apr-08 6:52 
GeneralClickOnce silent Pin
Eli Gazit16-Oct-07 2:17
memberEli Gazit16-Oct-07 2:17 
GeneralRe: ClickOnce silent Pin
Eli Gazit30-Oct-07 21:53
memberEli Gazit30-Oct-07 21:53 
Generalthere is a problem for this approach Pin
stevendonline10-Nov-06 8:11
memberstevendonline10-Nov-06 8:11 
GeneralRe: there is a problem for this approach Pin
DTMxxLLC30-Aug-07 16:28
memberDTMxxLLC30-Aug-07 16:28 
GeneralI like the idea Pin
_alank26-Sep-06 9:38
member_alank26-Sep-06 9:38 
GeneralRe: I like the idea Pin
saw123427-Sep-06 23:27
membersaw123427-Sep-06 23:27 
GeneralRe: I like the idea Pin
_alank28-Sep-06 1:47
member_alank28-Sep-06 1:47 
Questionwhy launch this way ? Pin
BillWoodruff1-Jun-06 9:09
memberBillWoodruff1-Jun-06 9:09 
AnswerRe: why launch this way ? Pin
saw12345-Jun-06 7:43
membersaw12345-Jun-06 7:43 
GeneralRe: why launch this way ? Pin
BillWoodruff5-Jun-06 8:16
memberBillWoodruff5-Jun-06 8:16 
GeneralRe: why launch this way ? Pin
saw123412-Jun-06 1:49
membersaw123412-Jun-06 1:49 
GeneralRe: why launch this way ? Pin
travis_1121121430-Apr-07 22:52
membertravis_1121121430-Apr-07 22:52 
GeneralRe: why launch this way ? Pin
saw123430-Apr-07 23:17
membersaw123430-Apr-07 23:17 
GeneralRe: why launch this way ? Pin
travis_112112141-May-07 1:04
membertravis_112112141-May-07 1:04 
GeneralRe: why launch this way ? Pin
saw12341-May-07 15:49
membersaw12341-May-07 15:49 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 23 May 2006
Article Copyright 2006 by saw1234
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid