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