User roaming profile ClickOnce application restore

chriscooper01

Chris Cooper

Posted on February 6, 2019

User roaming profile ClickOnce application restore

I know Officially Click Once does not support User roaming profiles, but not support does not mean that you can create a work around and this is my work around.

My solution is an application that sits outside the Click once application in a safe modifiable area. I’m using the C:\ProgramData folder. This application then get invoked by the Click once application to make a backup copy of its binaries and the linked registration elements within the user’s registration data. Once completed it then takes a copy of the original short cut and add its own short cut to the user desktop. Now the user will use this application to invoke the original Click Once application.

When the solution is invoked, it will check if a recovery is needed and then invoked the original Click Once application.

Full example in the example application on my GitHub repo. Use it, improve it or just use it as an starting point

The application

This application is split into two main elements; backup and recovery. You’re initial Click once application will initialise the required data and then invoke the application in backup mode.

Within the backup mode is split into two elements; binaries and registration data. When it backup the binaries it finds the original short cut link for the user on the desktop and replaces it with a link to itself.

The user will use the new link to open the original click once application, but as the link has been changed to invoke the recovery application. The recovery application will check if the AppData and registration data is already present, if not it will restore these and then invoke the original application as a click once application.

Full example in the example application on my GitHub repo. Use it, improve it or just use it as an starting point

Application data

First thing you need to initialise the recovery application from your original click once application. Below is an example code that shows what is needed.

This data can be set from your initial click once application, using the simple code snippet below.

Backup binaries

When the backup mode is invoked it will find the required application folders using ClickOnceLocation and FolderStartsWith value to find the required folders. These files are then copied to the RecoveryLocation location. It will copy the folders in the same structure.

Once the binaries have been collected it will get the manifest files from the manifest folder, copying all the files starting with FolderStartsWith. (This is used as it will be the same in both cases)

Now you need to get the Click once shortcut (file) and place it in the restore location. The application will look at the user desktop for a file that start with the ShortCurtStartsWith. This is needed as this is the key to make sure it uses the Click once logic. (This short cut is not a normal short cut, its a “.appref-ms” file)

The final part of this is to make sure there is a short cut to itself and it will use the ShortCurtDisplay value to set the display name.

Backup registration

The click once application will not work, making a binary backup and then restoring only. Click once requires user’s registration data as well.

You do need to get all the data from the below registration location, linked to your application.

Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0

Invoke

The original shortcut for your application has now has been replace with a short cut to this application. So once invoked it find out if it needs to restore or just invoke the application as normal.

Restore

As the user now uses this application to invoke their application, due to the new short cut. It will check if the Current folder is within the Click once location. If not present it will restore the registration and physical folders.

Registration

This will restore the users registration keys and values required for your click once application to run again.

The restore application will use the data collected from the backup and restore the registration to match, what it was at the below registration location.

Full example in the example application on my GitHub repo

\HKEY_CURRENT_USER\Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0

Binaries

The backup folder and files are copied form the backup location to the below location.

Full example in the example application on my GitHub repo

C:\Users\Chris.HEALTHDIAGNOSTI\AppData\Local\Apps\2.0 location

💖 💪 🙅 🚩
chriscooper01
Chris Cooper

Posted on February 6, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related