How to Set Default Apps on Windows 10 with a script?

12,918

For each of the filetypes that you want to set a default app for, find the filetype it is associated with.

For XML, at a CMD prompt execute this:

Assoc .xml

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/assoc

That will tell you the filetype is "xmlfile"

To set the default app for an "xmlfile", you'll use Ftype:

Ftype xmlfile=C:\Program Files (x86)\Notepad++\notepad++.exe %1

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ftype

Once you know the filetype for each of your extensions, add a line for each of them to your batch file.

Share:
12,918

Related videos on Youtube

Tyler Coleman
Author by

Tyler Coleman

Early Career IT specialist

Updated on September 18, 2022

Comments

  • Tyler Coleman
    Tyler Coleman over 1 year

    I am in an enterprise environment and I am trying to set the default apps on several systems by using a .bat script. This is what my script is doing, nothing complicated.

    @ECHO OFF
    dism /online /Import-DefaultAppAssociations:"%~dp0\MyDefaultAppAssociations_Modified.xml"
    

    However, I have noticed that it works on some work stations and not working on others. Any ideas on what would be causing that? The only thing I could think of is that the Program IDs in the XML file may change from computer to computer but I can't imagine that is the case. Any ideas or other methods on how to accomplish setting default apps are welcome.

    UPDATE: This script will either work complete and properly or it will not work at all. I have yet to see it where it only updates certain default apps.

    • Natsu Kage
      Natsu Kage over 4 years
      Hello. Just asking, but is it possible that there wasn't an administrator account active for the workstations that didn't work? Also, please specify if it doesn't work at all or just partially (some apps become default after the script) on these workstations to help others.
    • Tyler Coleman
      Tyler Coleman over 4 years
      I am executing the script from my admin account and then logging in with a dummy account to ensure that the default apps are being set properly. I read that this is actually a bug and the account that uploads this XML file does not get the change applied but the other accounts do. (This has been a bug since 2015)
    • DavidPostill
      DavidPostill over 4 years
      So is there anything of value in C:\WINDOWS\Logs\DISM\dism.log?
    • Tyler Coleman
      Tyler Coleman over 4 years
      @DavidPostill I don't seem to have that file location. Even when I unhide things.... I did use the Windows 10 Upgrade tool to upgrade from Windows 7 and I am wondering if that is causing my issue.
    • Natsu Kage
      Natsu Kage over 4 years
      Are these workstations all running the same Windows version? (1709, 1903, etc). The documentation on doing imports says that it may be an issue. Not sure on your side.
    • Tyler Coleman
      Tyler Coleman over 4 years
      @NatsuKage Deff not good these are all different builds as we are in the process of upgrading all windows 7 machines to windows 10. Although I would think that it would install the same image.... I am specifically using the Windows10Upgrade9252.exe from Microsoft.
    • Natsu Kage
      Natsu Kage over 4 years
      I'd try sending the batch again and see if there is a correlation between Windows build versions and the issue.For reference, the tips at the end mention issues with this: docs.microsoft.com/en-us/windows-hardware/manufacture/deskto‌​p/…
    • Ramhound
      Ramhound over 4 years
      "I am wondering if that is causing my issue." - There is no difference between a Windows 10 installation if it's been upgraded from an eligible version of Windows or if you perform a clean installation. Since you can upgrade Windows 10 to another version of Windows 10, in most instances, you are already dealing with an "upgrade installation".
  • DrMoishe Pippik
    DrMoishe Pippik over 4 years
    On Window 10, I've found assoc to be unreliable. For example, on one PC, "File association not found for extension .pdf", though clearly PDF files are associated with my default app, Sumatra, and show as such in Explorer and open correctly when double-clicked.
  • Mark
    Mark over 4 years
    Microsoft has introduced other means of associations over the years. While most apps use traditional associations they can use various DDE, COM, Context Menu extensions (how Word can open only HTML files it created). Also if Windows cannot find an extension it will look in the COM database for the COM filetype, then it will do content sniffing.