« Launching a ClickOnce Application from another ClickOnce Application | HomePage | masdoom rasmi »

Wednesday, May 31, 2006

Launching a ClickOnce Application from another ClickOnce Application

Source: http://www.codeproject.com/useritems/ClickOnceLauncher.asp 

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

2.    

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

3.     Find the application reference file from the start menu

4.    

1.     Using file explorer navigate to C:Documents and Settings(user)Start MenuPrograms(company)

5.     Create the Launcher application  

6.    

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

12:05 Posted in Blog | Permalink | Comments (0) | Email this

The comments are closed.