A bit of history
I see it all the time. People install some God-awful image viewer (*cough* Quicktime *cough*) and it overtakes their default image file associations. Annoying. As if image files weren’t already hunted pray. Furthermore we now also have Windows 10 (and to some extend 8 and 8.1) pushing us to use the Metro app: Pictures. Personally I don’t really mind Pictures that much, though I must admit to still using the classic Windows Photo Viewer. I find it a slightly faster when quick-stepping through a bunch of images using the arrow keys – and besides, it seems more clean and simple; which is a good thing.
A while back, long before Windows 10 was even a foggy wet dream at Redmond, I wrote a “reset script” which sets the most common image file types: jpeg/jpg, gif, png and tif/tiff, back to using Windows Photo Viewer. So when a similar issue landed on my desk the other day, I figured that I would take a look at it again and perhaps give it a much needed overhaul.
Addressing the problem
Ignoring completely that we could obviously just set these things from within the Windows GUI. Using ftype and assoc today, we need to take many things into account.
Ye olden days Windows (xp)
Back when everyone was running Windows XP, it was a simply matter og using the ftype and assoc commands to update the registry entries for each file association. Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cls @echo off ECHO Creation extension associations to filetypes... assoc .tif=TIFImage.Document assoc .tiff=TIFImage.Document assoc .jpg=jpegfile assoc .jpeg=jpegfile assoc .gif=giffile assoc .png=pngfile ECHO Binding filetypes to Windows Photo Viewer... ftype TIFImage.Document=rundll32.exe %windir%\system32\shimgvw.dll,ImageView_Fullscreen %%1 ftype jpegfile=rundll32.exe %windir%\system32\shimgvw.dll,ImageView_Fullscreen %%1 ftype giffile=rundll32.exe %windir%\system32\shimgvw.dll,ImageView_Fullscreen %%1 ftype pngfile=rundll32.exe %windir%\system32\shimgvw.dll,ImageView_Fullscreen %%1 |
(Note the double %% before the 1, which you need to omit if you run the commands directly from a prompt)
Newer Windows versions
However that obviously wouldn’t suffice for newer version of Windows. And not only due to the fact that the image viewer is different and therefore must be associated differently – but also since there are various things in place, which prevents you from changing the file associations that way (in addition to the obvious elevation concerns). If we simply ignore that however, and just update to script. It would look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cls @echo off ECHO Creation extension associations to filetypes... assoc .tif=TIFImage.Document assoc .tiff=TIFImage.Document assoc .jpg=jpegfile assoc .jpeg=jpegfile assoc .gif=giffile assoc .png=pngfile ECHO Binding filetypes to Windows Photo Viewer... ftype TIFImage.Document=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype jpegfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype giffile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype pngfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 |
Now that may actually be sufficient in certain cases. However, especially looking at Windows 10, there at a number of additional things which you need to take into account.
First of all. If you’re running a clean Windows 10 installation, you won’t even have Windows Photo Viewer available to you until you apply a small fix (Yes, I’m calling it a fix…deal with it).
Secondly, Windows 10 has triggers in place, which will detect if you change the file associations for certain file types in certain ways and reset these back to their default value (which means back to the Pictures app in this case). So in order to avoid that, we wan’t to start by setting a few registry entries BEFORE we change the associations, so that Windows minds it’s own business. To learn a bit more about this problem, you can start be reading this. For now though we simply need to set the following two registry entries. Using the command line methodology from earlier, it can be done as follows.
1 2 |
REG ADD "HKEY_CURRENT_USER\SOFTWARE\Classes\AppXk0g4vb8gvt7b93tg50ybcy892pge6jmt" /v NoOpenWith /t REG_SZ /d "" /f REG ADD "HKEY_CURRENT_USER\SOFTWARE\Classes\AppX43hnxtbyyps62jhe9sqpdzxn1790zetc" /v NoOpenWith /t REG_SZ /d "" /f |
Then we need to start fresh. The easiest way, I found, was to delete the registry entries for each file association before re-creating them from the command line. So let’s delete them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
reg delete "HKEY_CLASSES_ROOT\giffile" /va /f reg delete "HKEY_CLASSES_ROOT\.gif" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.gif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.gif" /va /f reg delete "HKEY_CLASSES_ROOT\pngfile" /va /f reg delete "HKEY_CLASSES_ROOT\.png" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.png" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.png" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.png" /va /f reg delete "HKEY_CLASSES_ROOT\jpgfile" /va /f reg delete "HKEY_CLASSES_ROOT\.jpg" /va /f reg delete "HKEY_CLASSES_ROOT\.jpeg" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.jpeg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpeg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.jpg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.jpeg" /va /f reg delete "HKEY_CLASSES_ROOT\TIFImage.Document" /va /f reg delete "HKEY_CLASSES_ROOT\.tif" /va /f reg delete "HKEY_CLASSES_ROOT\.tiff" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.tif" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.tiff" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tiff" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.tif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.tiff" /va /f |
And then we can run the script from ealier to associate the extensions correctly.
The completed Windows 10 script
Now looking at the complete script, it should look something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
cls @echo off echo Adding registry keys to avoid having Windows 10 re-hijack our stuff reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\AppXk0g4vb8gvt7b93tg50ybcy892pge6jmt" /v NoOpenWith /t REG_SZ /d "" /f reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\AppX43hnxtbyyps62jhe9sqpdzxn1790zetc" /v NoOpenWith /t REG_SZ /d "" /f echo DELETING .gif reg delete "HKEY_CLASSES_ROOT\giffile" /va /f reg delete "HKEY_CLASSES_ROOT\.gif" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.gif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.gif" /va /f echo DELETING .png reg delete "HKEY_CLASSES_ROOT\pngfile" /va /f reg delete "HKEY_CLASSES_ROOT\.png" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.png" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.png" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.png" /va /f echo DELETING .jpg/.jpeg reg delete "HKEY_CLASSES_ROOT\jpgfile" /va /f reg delete "HKEY_CLASSES_ROOT\.jpg" /va /f reg delete "HKEY_CLASSES_ROOT\.jpeg" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.jpeg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpeg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.jpg" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.jpeg" /va /f echo DELETING .tif/.tiff reg delete "HKEY_CLASSES_ROOT\TIFImage.Document" /va /f reg delete "HKEY_CLASSES_ROOT\.tif" /va /f reg delete "HKEY_CLASSES_ROOT\.tiff" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.tif" /va /f reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\.tiff" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tiff" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.tif" /va /f reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Roaming\OpenWith\FileExts\.tiff" /va /f ECHO Creation extension associations to filetypes... assoc .tif=TIFImage.Document assoc .tiff=TIFImage.Document assoc .jpg=jpegfile assoc .jpeg=jpegfile assoc .gif=giffile assoc .png=pngfile ECHO Binding filetypes to Windows Photo Viewer... ftype TIFImage.Document=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype jpegfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype giffile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 ftype pngfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %%1 |
Remember to run it elevated. Enjoy!
1 comment
This has changed a bit in the recent versions of Windows (1803 / 1903) and consequently it no longer works as detailed above. You may still need to do some of the operations – and running the script wont hurt. However you’ll have to set the “Photo viewer” through the Default Apps overview found under Settings.