Ashkan
Ashkan

Reputation: 378

Automate the Default Program Association

I'm Writing a batch script to automate the process of changing default program association for specific file types.

The file types are defined perfectly and i'm using this command to change default program for opening them for example:

ftype giffile="%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll" "%1"

But after running this, nothing will change!

"giffile" is just an example of file type that i'm trying to change default program association.

What am i missing ? (suggestions would be great if there is a better solution)

EDIT: with ftype i could just be able to add the program to the "open with" list and that doesn't change default program used to open specific filetype.

Upvotes: 3

Views: 3001

Answers (1)

Jan Uhlig
Jan Uhlig

Reputation: 82

Oh that is a good one, and it took me several hours to find the misbehaviour. To test this, I refer to the .txt file. Problem is, as far as I figured, that your datatype is already opened with another system-internal program. In my case, .txt is connected to Worpad. So if you mess around with the registry (nothing else is assoc and ftype doing), it will always fallback to Wordpad, no matter what. Even changing it to another program as you try, it will fallback.

In order to verify this bevaviour you can simply think of a new (unconnected) fileextension and try your program association with it. For example .log was not associated for my system, so doing the following steps for a .log file immediately changed its opening program the way I wanted. If log is already connected for you, think of something comepletely new.

So Step1 is to not let it fallback to Wordpad. As Wordpad is an Optional Feature of Windows, we first have to uninstall it. This is easiest in Software->Programs->Optional Features and select it there to be uninstalled. As you prefer a programatical way with a batch script i can recommend the dism command, which can be reversed by replacing "Remove" with "Add".

dism /Online /Remove-Capability /CapabilityName:Microsoft.Windows.WordPad~~~~0.0.1.0

After this, if you doubleclick a txtfile it will not be opened by default anymore. Then, as stated in many different answers to this question, all you need to change a filextension to behave as you wish is to call

assoc .txt

That will give you "txtfile" as return value. Then connecting the txtfile type with the program you wish to have it opened type. Make sure it is txtfile and not textfile. Im a bit confused which of both it was for me, I think the windows standard is txtfile. Typos can be ugly here.

ftype txtfile="exampleprogram.exe" "%1"
  • Please remember here, that in batch you need to use %%1 because the first % is escaped. If that %1 is omitted, the program starts on doubleclick but will not present the acutal opened file.
  • The quotes are only used because most programs have a space in their filepath.
  • My example deinstalls the Wordpad. While it should not be problem to redirect all filetypes to the program you with to replace .txt with, remember that .bat, and .ini files are per default also opened by Wordpad, maybe some more.

I included the txtfile example as this worked for me and you clearly stated the giffile is just an example. Adaption to your giffile difference is to get rid of the photos app first. Research says this can be also be done programatically.

Upvotes: 1

Related Questions