DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide
  • Why Mocking Sucks
  • Moving PeopleSoft ERP Data Between Databases With Data Mover Scripts

Trending

  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  • Build an MCP Server Using Go to Connect AI Agents With Databases
  • Failure Handling Mechanisms in Microservices and Their Importance

How To Run a ClickOnce Application on Startup

By 
Keith Elder user avatar
Keith Elder
·
Apr. 20, 09 · News
Likes (0)
Comment
Save
Tweet
Share
31.2K Views

Join the DZone community and get the full member experience.

Join For Free

When .Net 2.0 launched several years ago, WinForm developers got a brand new technology baked into the framework that allowed WinForm applications to be deployed similar to a Web application.  The technology was called ClickOnce.  ClickOnce has seen a few enhancements since it’s initial release such as the ability to add a desktop icon when an application is installed along with better support for ISVs.  One feature still missing from ClickOnce is to make an application start automatically after login.  Let’s solve this problem.

The Problem

When a ClickOnce application is installed the user doesn’t know the directory location it is installed in on their computer.  Honestly they shouldn’t care.  Not only does the user not know, but the developer doesn’t know either!  ClickOnce applications are installed in random directories on each computer in a hidden folder within the user account called the “AppData” folder.  For example, here is a screen shot where the ClickOnce version of Witty Twitter that I publish on this site is installed on my newly built machine.

As you can see it is in a random place and this is the problem because a ClickOnce application doesn’t have a fixed path like c:\program files\somewhere\myapp.exe.  Why?  Well, because the ClickOnce team at Microsoft didn’t build in the ability for Developers to specify a location as to where the application is installed, nor can the user select one.  The purpose of a ClickOnce app is the end-user clicks a URL that ends in .application and the application installs.  Simple, quick, easy.  If the application path was set outside of the user’s account it would require escalated permissions.  A feature of ClickOnce is it allows the user to install an application without administrative permissions on the computer (great for internal apps at companies for example).  Since the ClickOnce apps are installed in the user’s local directory and randomized as to their whereabouts, we can’t place a shortcut URL in the startup folder that points to the executable.

Now some of you might be thinking that a Developer can programmatically figure out the location of the executable and place the shortcut in the Startup folder within the menu, thereby allowing the application to start.  That would be the wrong thing to do.  The reason is ClickOnce applications version themselves as they are installed.  If you took this approach, the next time the application was updated, a new version would be installed and the old version still remains.  Essentially there are two versions on the machine (this is a feature because it allows end-users to roll back to the previous version if they want to in case the latest version of the application is broke).  As you see, creating a shortcut programmatically and placing it in the startup folder on the machine won’t work because it is constantly changing locations.

The Solution

The solution to the problem is actually really simple.  So simple in fact it escapes most.

Remember that a ClickOnce application is launched from a URL ending in .application.  For example, the Witty Twitter application I publish has a URL like the following:

http://keithelder.net/software/witty/witty.application

The .application extension is something your computer knows how to process after the .Net framework gets installed. 

What most developers do is they open up the folder the location where the ClickOnce application installed the shortcut to view the shortcut in notepad.  Here’s an example  using Witty:

If we view the Witty shortcut in Notepad++ it looks like this:

The first thing you’ll notice is the extension of this shortcut is different, it ends with .appref-ms.  So what happens is developers copy this file to the startup folder, but then it doesn’t work in all cases.  It will work on some versions of Windows but not others.

Here’s the fix.  Right click on your desktop and in the menu create a new shortcut.

Next, enter the URL of your application.  Here’s a sample using Witty:

Click next and give it a name:

After saved, open the shortcut in notepad and remove everything but the first two lines.  You should have something like this left when you get done:

[InternetShortcut]
URL=http://keithelder.net/software/witty/witty.application

Now you have your shortcut.  Wait, that’s just a standard Internet Shortcut?  Right!  That’s all you need since the application is launched from a URL anyway.  You’ll notice after doing this the new shortcut is showing the default browser’s icon (not your application icon), this is perfectly ok.  Now that you have your file, simply drag and drop the shortcut into the Startup folder.  The next time the computer boots, the application will automatically launch. 

If you are a developer you are home free now because programmatically writing a file to the user’s Startup folder with this information is simple.  In your application you can place a menu option to start the application on startup or not. 

Their are two downsides using the method I can think of.  One, your application shows the default browser’s icon.  Secondly, when the computer launches the browser will open for a split second to launch the application but then it closes (at least that’s been our experience).

 

application

Published at DZone with permission of Keith Elder. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide
  • Why Mocking Sucks
  • Moving PeopleSoft ERP Data Between Databases With Data Mover Scripts

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!