Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 cannot associate file to clickonce application

I have a clickonce application which works fine on windows 7. When it's being installed on a windows 10 machine, it seems that the specific file for our application cannot be properly associated to the clickonce application.

If I click right on the file, and choose "open with", I can see in the list "ClickOnce Application Deployment Support Library". But if I choose this option, I get a message saying "this application cannot be executed on your PC". If I decide to choose directly the .exe file of the clickonce application (C:\Users\xxx\AppData\Local\Apps...), it will not work properly (version & update detection).

I am able to install my application and I am able to run it properly from the start menu. The only thing not working is the file association. I have tried to uninstall, and reinstall, but it doesn't change anything.

Edit : I have installed the application on another windows 10 machine, and everything works fine (including the file assocation "automatically when installed & when specifiying it manually"). So I think the problem is not "generic" for all windows 10 machines.

like image 432
montueron Avatar asked Jun 01 '16 07:06

montueron


2 Answers

I was able to reproduce montueron's issue. After turning on logging (https://msdn.microsoft.com/en-us/library/dd996997.aspx) and setting the logging location (https://msdn.microsoft.com/en-us/library/ms404265.aspx), I was able to determine that the file association was being skipped: File association for ".tiff" skipped, since another application is using it.

Here is what I did to solve my problem on Windows 10. My goal is to associate my ClickOnce program, "Tif2PDF", with .TIF and .TIFF image files.

  1. Create a unique file association in the ClickOnce Publish settings in Visual Studio 2017. I am not using .TIF at this time, we just want to create the appropriate registry entry under HKCU\Software\Classes\Tif2PDF which will get removed in the un-install process.

    Properties->Publish->Options->File Associations.
    extension=.tif2pdf
    description=Tif2PDF
    progID=Tif2PDF
    icon=Resources\Tif2PDF.ico
    
  2. In the Tif2PDF program startup process, we need to add registry settings when it is installed - only run when it is updated:

    if ( System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
                   && ApplicationDeployment.CurrentDeployment.IsFirstRun )
    
    Computer\HKEY_CURRENT_USER\Software\GuardTech\PDFTool\Capabilities\FileAssociations
    .tif="Tif2PDF"    
    .tiff="Tif2PDF"
    

These two entries tell windows to use the HKCU\Software\Classes\Tif2PDF entry for TIF and TIFF file types.

  1. Tell Windows this is a registered application. This value points to the key created in step 2.

    Computer\HKEY_CURRENT_USER\Software\RegisteredApplications
    Tif2PDF="Software\Tif2PDF\Capabilities"
    

At this point, you should see an option in Windows Explorer under "open with" called "ClickOnce Application Deployment Support Library". It will work at this point, but let's add a label and icon.

  1. Create key and values below.

    string iconSourcePath == Path.Combine(System.Windows.Forms.Application.StartupPath, @"Resources\Tif2PDF.ico");
    Computer\HKEY_CURRENT_USER\Software\Classes\Tif2PDF\Application
    ApplicationIcon=iconSourcePath
    ApplicationName="Tif2PDF"
    
  2. You program will need to handle command line arguments a little differently

    //Get the normal command lines arguments in case the EXE is called directly
    List<string> argList = new List<string>(Environment.GetCommandLineArgs());
    argList.RemoveAt(0); //Remove the application.EXE entry
    
    // this is how arguments are passed from windows explorer to clickonce installed apps when files are associated in explorer
    if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments?.ActivationData != null )
    {
    argList.AddRange( AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData);
    }
    
  3. We should try to cleanup these registry settings when we un-install the program by following thedracle's post Custom action on uninstall (clickonce) - in .NET

like image 76
J.J. Willis Avatar answered Oct 17 '22 05:10

J.J. Willis


I just created a test application as Administrator (Windows Forms Application) using Visual Studio 2015 (< 5 minutes)

1) Under Properties/Publish/Options/File Associations added an entry:

Extension: .abcd

Description: test

ProgID: 2

Icon: An icon file

2) Under Properties/Publish I pressed Publish Now and ran Setup

3) Created a text file, renamed it to test.abcd

It is working as expected under Windows 10, so you could create a test application / verify that it's working and see what the differences are compared to your existing application.. 32/64 bit, framework, signing etc.

like image 20
A.J.Bauer Avatar answered Oct 17 '22 05:10

A.J.Bauer