1

I want to get independent of installed apps and share most of my apps as portable versions in a cloud drive. So my idea is whenever I sit on a new device I just sync my cloud drive and start some kind of process which installs my setup.

By installing I mean setting up my windows settings and so on. And I want to set the default apps per filetype. For example bind .txt files to d:\cloud\notepad++\notepad++.exe

Here is a simplified script how I try to do this. I stripped ErrorActions and so on to make it more readable.

$exe = "d:\cloud\notepad++\notepad++.exe"
$app = "notepad++.exe"
$ext = ".txt"

# Remove old associations
Remove-Key -Key "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$ext"
Remove-Key -Key "HKCR:\$ext"
Remove-Key -Key "HKCR:\$app"

# Setup new associations
cmd /c assoc $ext=$app
cmd /c ftype $app="$exe" "%1" "%*"
Set-ItemProperty -Path "HKCR:\$app" `
                    -Name "(Default)" `
                    -Value "Text file" `
                    -Type String  

This kind of works. Whenever I try to open a .txt file now it asks me which app to use and pre-selects notepad++.
Okay that's kind of annoying but I could live with that. Although. When I check always use this app to open .txt files it gets simply ignored. I always get this dialog.

enter image description here

1 Answer 1

0

Although this post is over 3 years old, the SetUserFTA might help you. See references here and here.

It worked for me to programmatically set the default browser in Windows 10 and it should work for any other file types.

EDIT Here is what I did:

  1. Download the latest SetUserFTA from here and inzip to extract the SetUserFTA.exe.

  2. Create a BAT file containing the following:

    i. Change directory (cd) to the folder (path to) where SetUserFTA.exe is located.

    ii. A number of lines/instructions defining the desired default association for each file type. For example, to set Firefox as my default web browser, I added the following lines:

    REM web browser: Firefox
    SetUserFTA  http FirefoxHTML
    SetUserFTA  https FirefoxHTML
    SetUserFTA  .htm FirefoxHTML
    SetUserFTA  .html FirefoxHTML
    
    REM ... add any other file extensions here
    
  3. Run the BAT file, either on-demand or you can schedule it using Task Scheduler. Make sure to run the BAT file "with the highest permissions" (it needs that to be able to update the Windows registry) from your user context.

1
  • Welcome to SuperUser! While this link may answer the question it is better to quote the most important parts from it as the original site might change or get deleted entirely, rendering your answer useless. Jul 14, 2022 at 20:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .