Set File Type Association Default Application Command Line Windows 10 UserChoice Hash Internal Method

? SFTA.exe Latest Update 2020-09-14

Tested in: Windows 8, Windows 8.1, Windows 10 Version 1511, Windows 10 Version 1709, Windows 10 Version 1803, Windows 10 Version 1809, Windows 10 Version 1903, Windows 10 Version 1909, Windows 10 Version 20H2, Windows 11 Pro Version 21H2


Recently one of my clients has asked me to change the default program associated with the extension  . pdf  to Acrobat Reader DC on Windows 10, all in an automated way. The first thing that comes to mind is to change it through the registry by editing the registry key UserChoice.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice
UserChoice Registry Key – Hash – ProgId

Hash entry that is generated automatically by Windows to validate the integrity of file type association.
ProgId entry is the Registered Application Id that handle the file type.

The main problem is that in recent versions of Windows 8/10 This key is protected by a hash associated with the file type, and succeeding in editing it without generating the valid hash the association is automatically restored to the default application.

Doing a quick search on Google I found some ways to do it, using GPO(Group Policy Object) or importing a .xml association file with DISM.exe, but they were a little extensive processes, after a deeper search and taking into account that my client needed a quick fix I found this little command line tool SetUserFTA.exe created by Christoph Kolbicz which complied with what was required and I opted to use momentarily, however I was intrigued to be able to include this method directly in an application developed in another language such as C++, AutoIt, Pascal or PowerShell.

After a couple of days fighting against Windows and doing some Google research, I manage to find the method that uses Windows internally and develop a code to implement in the application of my client.

I developed a small command line tool in PureBasic to perform this task over Windows 8/10 which is very simple to use.

SFTA Command Line Tool

Sample Usage:

Set Acrobat Reader DC as Default .pdf reader:

SFTA.exe AcroExch.Document.DC .pdf

Set Sumatra PDF as Default .pdf reader:

SFTA.exe Applications\SumatraPDF.exe .pdf

Set Google Chrome as Default for http Protocol :

SFTA.exe ChromeHTML http

I hope this tool will be useful.

SFTA Changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

1.3.1 – 2020-09-14

Changed

  • Hash Algorithm Raw PureBasic Code

1.3.0 – 2020-04-24

Added

  • Add Protocol Support
  • Add Icon Support for File Type

1.2.1 – 2019-12-13

Added

  • Add –list Show All Application Program Id

Fixed

  • Fix –get command

1.2.0 – 2019-12-12

Added

  • Add Hash Algorithm Method to handle the latest Versions of Windows 10

1.1.0 – 2019-08-07

Added

  • Add –reg Register Application Program Id
  • Add –unreg Unregister Application Program Id
  • Add –debug Display Debug Information
  • Add Windows 10_1115 Support – Thanks to Mehdi

1.0.0 – 2019-01-22

First Release


If you find this useful, a small donation would be greatly appreciated.

  • Bitcoin
  • Ethereum
  • Binance coin
  • Litecoin
Scan to Donate Bitcoin to 1Lrei7nhGeazvnJZHduGCduER2thjwD12F

Donate Bitcoin to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin

Scan to Donate Ethereum to 0x6BF5A047ebE7563D98e60887ab6e9485cB3564FF

Donate Ethereum to this address

Scan the QR code or copy the address below into your wallet to send some Ethereum

Scan to Donate Binance coin to bnb136ns6lfw4zs5hg4n85vdthaad7hq5m4gtkgf23

Donate Binance coin to this address

Scan the QR code or copy the address below into your wallet to send some Binance coin

Tag/Note:- BEP2
Scan to Donate Litecoin to LfLJrcNEfA8Td8n2R3eV6AV3QTfNp8XgBX

Donate Litecoin to this address

Scan the QR code or copy the address below into your wallet to send some Litecoin

Other Method? Contact Us: hello.danysys@gmail.com

87 thoughts on “Set File Type Association Default Application Command Line Windows 10 UserChoice Hash Internal Method

  • I tried the command line:
    sfta.exe -h
    this works fine.

    However, the next command line:
    sfta.exe -g “.txt” returns : “Error. Unable To Query Associated Application” when my .txt files are associated with notepad.exe.

  • Hi Are you willing to provide source for this application so it can be confirmed it doesn’t do anything malicious?

  • I tried to change association for .htm but the only thing it did was to break the existing association. Next time when I double-clicked a .htm file Windows asked me what program I wanted to open the file with.

    Command I used: sfta –reg “C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe” “.htm”
    OS: Windows 10

    Next I checked the code from github. That does not seem to include calculation of the Hash.

    Dont know what I am doing wrong.

    Asad

    • Hello @Asad, Seems to be you have already installed Chrome so It already has Program ID registered. You just need to do this.

      SFTA.exe "ChromeHTML" ".htm"

      About “calculation of the Hash” It’s is done by the interface IApplicationAssociationRegistrationInternal internally.

      Regards

  • Looks like the tool is not working.

    PS C:\Windows\System32\WindowsPowerShell\v1.0> sfta -d “FoxitReader.Document” “.pdf”
    [2019.10.17 16:28:15] OSVersion = 110
    Windows Version: Windows 10
    Windows ReleaseId: 1903
    Windows Build: 18362
    Windows ProductName: Windows 10 Enterprise
    [2019.10.17 16:28:15] Is Windows 10
    [2019.10.17 16:28:15] FAIL AssociationRegistration Instance

  • Not working 🙁
    C:\Users\User\Desktop\SFTA-1.2.1>SFTA.exe -d “7-Zip.rar” “.rar”
    [2020.01.21 10:56:00] OSVersion = 110
    Windows Version: Windows 10
    Windows ReleaseId: 1909
    Windows Build: 18363
    Windows ProductName: Windows 10 Enterprise
    [2020.01.21 10:56:00] Is Windows 10
    [2020.01.21 10:56:00] FAIL AssociationRegistration Instance
    [2020.01.21 10:56:00] Experience String Found
    [2020.01.21 10:56:00] Hash: LPFBiCwvmtk=
    [2020.01.21 10:56:00] Write Reg UserChoice OK
    [2020.01.21 10:56:00] SetFileTypeAssociation Hash Method OK

    • Hello @Alexander, Did you try with other application? maybe a PDF for testing. Are you sure 7-Zip.rar is the correct Application ID for 7zip? Make sure to pass the debug parameter (-d) at the end.
      Updated:
      Seems to be 7-Zip does not register the Application ID by default. You would need to go to 7-Zip’s menu Options and add .rar type, it registers Application ID and this command will work SFTA.exe “7-Zip.rar” “.rar”. If you want to avoid manually change 7-zip options you can use SFTA’s -r command, It will register the Application ID and associate it automatically with this command SFTA.exe -r “C:\Program Files\7-Zip\7zFM.exe” “.rar”

      • The same 🙁

        C:\Users\User\Desktop\SFTA-1.2.1>SFTA.exe -r “C:\Program Files\7-Zip\7zFM.exe” “.rar” -d
        [2020.01.21 17:12:07] OSVersion = 110
        Windows Version: Windows 10
        Windows ReleaseId: 1909
        Windows Build: 18363
        Windows ProductName: Windows 10 Enterprise
        [2020.01.21 17:12:07] Is Admin
        [2020.01.21 17:12:07] Application Program Id = “SFTA.7zFM.Application”
        [2020.01.21 17:12:07] ASSOC Return = 0
        [2020.01.21 17:12:07] FTYPE Return = 0
        [2020.01.21 17:12:07] Is Windows 10
        [2020.01.21 17:12:07] FAIL AssociationRegistration Instance
        [2020.01.21 17:12:07] Experience String Found
        [2020.01.21 17:12:07] Hash: z7+k4YXuUig=
        [2020.01.21 17:12:07] Write Reg UserChoice OK
        [2020.01.21 17:12:07] SetFileTypeAssociation Hash Method OK

      • And this is for Adobe Acrobat XI Pro 11.0.23 and pdf extension. It change the icon, but when I click the pdf file – annoying dialog with program selection popups (Acrobat is selected already in that dialog, and if I tell to use that app everytime – everything is OK).

        C:\Users\User\Desktop\SFTA-1.2.1>SFTA.exe “Acrobat.Document.11” “.rar” -d
        [2020.01.21 17:15:25] OSVersion = 110
        Windows Version: Windows 10
        Windows ReleaseId: 1909
        Windows Build: 18363
        Windows ProductName: Windows 10 Enterprise
        [2020.01.21 17:15:25] Is Windows 10
        [2020.01.21 17:15:25] FAIL AssociationRegistration Instance
        [2020.01.21 17:15:25] Experience String Found
        [2020.01.21 17:15:25] Hash: TM8D+ZHHTCo=
        [2020.01.21 17:15:25] Write Reg UserChoice OK
        [2020.01.21 17:15:25] SetFileTypeAssociation Hash Method OK

        • Try this command and post console output.

          SFTA.exe -r "C:\Program Files\7-Zip\7zFM.exe" ".rar" -d

          I’ll do some tests to check what’s going wrong because It’s working fine in my side.

          Regards

          • Seems have found the problem – by bad. Need to use:

            [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Explorer]
            “NoNewAppAlert”=dword:00000001

            or

            [HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Explorer]
            “NoNewAppAlert”=dword:00000001

            and the popup dialog dissapears.
            Sorry.

  • Hi Danny, thanks for this tool. It seems like it doesn’t work for the default browser setting (which modifies the protocols http and https, additionally to the .htm and .html file extensions.
    When you use SFTA.exe MSEdgeHTM .https the modification needs to be written here: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice

    Same with .http. Is there any chance you can add the different registry paths for these two protocols?

  • Hi Dany,
    Thank you so much for this tool! I had never seen PureBasic project in my life before I saw this so I guess I got to geek out a little bit as I was going through this. I still suck at reading it though. I love that this is open source, but do I understand correctly that all of this is readable code except for the GenerateHash function which is hidden away in the hash.a (compiled in C?) file?
    My apologies if this is a silly basic coding question I should know the answer to.. but any pointer you could provide would be greatly appreciated.
    Cheers.

    • Hi, I got the hash using a debugger so It was a very messed C routine that I compiled to static library. I’m planning to convert the hash routine to raw PureBasic code, but haven’t had a chance to do it yet.

      Regards

      • Hi Dany,
        Thank you for the quick reply! That would be awesome and would really help so I’ll look forward to that.
        Cheers.

  • Hi, Danny. Thanks for your great work! It works like a charm. But I want to ask a further question. I’m trying to associate FTP protocol with a custom program. And in this custom program I intend to forward the FTP url (a file on FTP) to different applications according to the extension of the file (on FTP) and the system default applications settings. I can get all the system associated ProgIds with the help of your SFTA.exe. But how can I invoke the application (with a proper format) if I know the ProgId? Wonder if you have any suggestions on achieving this? Thanks!

    • Hello Zezheng. I’m not sure If I understand what you’re trying to do. But Basically You would associate the FTP protocol with your Custom App like this:

      SFTA.exe "YourAppID" "ftp"

      If You don’t have your App registered:

      SFTA.exe --reg "C:\MyCustomApp.exe" "ftp"

      After that You will be able to pass the FTP url as parameter to your custom application like this using a cmd prompt:

      start ftp:\\YourFTPFile.txt"

      That will invoke your CustomApp with the url as parameter.

      Regards

  • Hola Amigo muchisimas gracias funciona excelente, pero tengo una duda, hay manera de que al ejecutar SFTA.exe AcroExch.Document.DC .pdf funcione para todos los usuarios en el equipo? ya que actualmente solo funciona con el usuario en donde se ejecute, y al iniciar sesion en otro usuario no está acrobat predeterminado.
    De antemano agradezco tu respuesta.
    Saludos desde Guatemala

    • Hola Francisco. Actualmente funciona solo para el Usuario donde se ejecuta. Intentare agregar esa característica en la próxima versión.

      Saludos

      • Muchisimas Gracias Dany, me serviría mucho para cambiar opciones remotas pormedio de psexec y que se apliquen a todos los usuarios de una sola computadora.
        Gracias nuevamente

  • Hi Dany, thanks a lot for your work. It is highly appreciated that you share your source code!

    Do you know if there are any plans to make a new Powershell version for 1809 and higher ?

  • Hello
    I’m really looking forward to the powershell version.
    Although if I could get the hash algorithm privately, I could already use it without the full script and thank you very much for that.

  • Thanks, this works wonderfully. I’m confused as to why they make it so hard for us to set an association for specific users. Is this some sort of protection that MS implemented, and will they eventually break your tool?

    • Hello! I’m pretty sure Microsoft added it for security reasons. I’m not sure if they will make changes that break my tool anyway. I will try to keep it updated when it happens. Regards

  • Hello, great program for windows10.
    unfortunately does not work on windows 8.1, the hash is incorrect.

      • As for the hash, I’m probably wrong. but still does not work.

        Console output:
        C:\Windows\system32>C:\Users\admin\Desktop\win10assoc\SFTA.exe -d AcroExch.Document.DC .pdf
        [2021.05.25 17:28:19] OSVersion = 100
        Windows Version: Windows 8 1
        Windows ReleaseId:
        Windows Build: 9600
        Windows ProductName: Windows 8.1 Single Language
        [2021.05.25 17:28:19] Hash: o/IPBtOjbuY=
        [2021.05.25 17:28:19] Unable To Delete UserChoice
        [2021.05.25 17:28:19] Write Reg UserChoice OK
        [2021.05.25 17:28:19] SetFileTypeAssociation OK

  • Hi DM,

    I’d prepared to deploy the application in a hospital environment. Without seeing what it is dong in HASH.A is a worry for us.

    Our target machines will be WIndows 10 21H1. Under test.

    Also can the donation be done via PayPal rather than BitCoin?

    Regards

    • Hash.a was removed. It uses raw code now. You can check source code of the tool, or check our PowerShell version.

      About donation, I’m from a third world country , so Paypal does not support my country. Probably you could use other method. I’ll email you. thank you

      Regards

  • Would you able to share the code?
    is it secure to execute? since we don’t have any visibility whether the cmd line change any other security settings, etc. bit worried? pls advise?

  • Appreciated. I could find the file from GitHub -.> SFTA.PB,
    How do I convert the .pb file to .exe command line.

  • Hello this Khaja From India I cannot set Vlc Media player as default for mp4 files using the following commands

    SFTA.exe Applications\VLC.exe .mp4

    or

    SFTA.exe VLC.mp4 .mp4

    I don’t know what is the mistake in these commands.

    • Hello Khaja. VLC uses different Application ID for each extension. So to set VLC default for .mp4 extension you should do it like this:

      SFTA.exe "VLC.mp4" ".mp4"

      Regards

  • How would I add a parameter to the default program that I’m wanting to set?

    I love the ShareX image editor and I would like to make it the default image editor for Windows.

    However, when I select the ShareX.exe process, it just processes the image like it would a capture instead of opening the image editor.

    Instead, There is -imageeditor “file path” command.

    How do I set “C:\Program Files\ShareX\ShareX.exe” -imageeditor as the default handler for image files?

    Thanks in advance!

    • Hello. I’ve notice application does not register an Shell Command for using -imageeditor so you would need to register one before set as default for your extension. So you need to do the following:

      powershell -ExecutionPolicy Bypass -command "& {New-Item -Path "HKCU:\Software\Classes\ShareX.image\shell\open\command" -Force | New-ItemProperty -Name '(Default)' -Value '""C:\Program Files\ShareX\ShareX.exe""" -imageeditor """%1"""'; . .\SFTA.ps1; Set-FTA 'ShareX.image' '.jpg' }"

      Regards

      • Thanks so much for the quick reply. However, I get the error:

        The string is missing the terminator: ‘.

        I added an ‘ to the end of the statement but same error.

        and FYI, your blog has bottom scroll-bars disabled but the comments don’t have word-wrap enabled.

  • hoho, much thanks. super thanks for ” Register Application + Set Protocol Association”. now i can register any program to take over http protocol. windows 10 really made that one difficult. if anyone asks why i’d want to do this, its because sometimes im in a video game and theres a link (which i dont know is a http link) and clicking it in game will open my web browser with 400 tabs , crushing my ram and wasting my time.

    now with this program, i am able to open links in a smaller program so it doesnt waste my time. unbelievable.

  • Hello from Japan.
    I tried below command but couldn’t set file type association.

    SFTA.exe Acrobat.Document.DC .pdf

    MSEdgePDF was setted as default application.

    my environment:
    OS: Windows 10 Pro 21H2
    Applicaiton: Adobe Acrobat Reader “64bit” version

    I can’t set as default because your tool doesn’t support Windows 10 Pro 21H2?

    • Hello SamuraiX, did you try with other application to be sure It’s not working and to be sure Acrobat.Document.DC is the correct Acrobat Application ID. I’ve tested with Windows 10 Pro 21H2 before and it worked.

      • Thank you for your replying, Danyfirex.

        I tried below command but could not set correctly again.

        SFTA.exe FoxitReader.Document .pdf

        I set file type association to Adobe Acrobat DC “manually”, then

        HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice\ProgID

        was set to “Acrobat.Document.DC”.

        So, I thought “Acrobat.Document.DC” is correct…I was wrong?

  • Hello,

    I am interested in this, but VirusTotal shows a couple of vendors that mark it as malicious. Any ideas on that? Also did you ever get it put on to GitHub like you had mentioned from August 20, 2019?

    Regards,
    Mr. Bill

  • It looks like sfta.exe doesn’t work on a freshly installed windows 10.
    If you manually change (on a freshly installed windows 10) the association to adobe reder dc, then manually change it to ms edge, then run SFTA.exe “AcroExch.Document.DC” “.pdf”, then the association changes to adobreaderdc and everything works.
    I understand correctly that on a freshly installed win10 it is enough to execute SFTA.exe “AcroExch.Document.DC” “.pdf” and *.pdf files should open by double clicking?

  • Using the PowerShell version, when I use: Get-Help .\SFTA.ps1 -full

    I get the result:
    Get-Help : Get-Help could not find .\SFTA.ps1 in a help file in this session. To download updated help topics type:
    “Update-Help”. To get help online, search for the help topic in the TechNet library at
    https:/go.microsoft.com/fwlink/?LinkID=107116.

    Any idea what I’m doing wrong?

    • Hello, I think your issue is related to execution policy.
      Run It like this:
      powershell -ExecutionPolicy Bypass -Command Get-Help .\SFTA.ps1 -full

      Regards

      • Hmmm…doesn’t seem to make a difference.

        Get-Help : Get-Help could not find .\SFTA.ps1 in a help file in this session. To download updated help topics type:
        “Update-Help”. To get help online, search for the help topic in the TechNet library at
        https:/go.microsoft.com/fwlink/?LinkID=107116.
        At line:1 char:1
        + Get-Help .\SFTA.ps1 -full
        + ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
        + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

        I’m using PS 5.1 (19041) (1682).

        I just tried it in 7.2.6 and I get
        Get-Help: Get-Help could not find .\SFTA.ps1 in a help file in this session. To download updated help topics type: “Update-Help”. To get help online, search for the help topic in the TechNet library at https://go.microsoft.com/fwlink/?LinkID=107116.

        So I did an Update-Help but that didn’t have any affect.

        I assume I’m doing something wrong, but I’m not sure what.

  • @Danyfirex

    Is there a parameter for the file Association for all users on a computer?

    Kind regards,

    Peter

Leave a Reply

Your email address will not be published. Required fields are marked *