Windows 10

Batch File To Set Default Programs in Windows 10

In this tutorial, we’ll explore how to set default applications for specific file types in Windows 10 using a batch script. This approach leverages native command-line tools like assoc and ftype and is useful for configuring environments, automating deployments, or managing shared workstations.

Batch files execute a series of DOS (Disk Operating System) instructions—making them an efficient way to automate repetitive system configurations.
 
 

🔍 Step 1: Identify the File Type with assoc

Before assigning a program to a file extension, you must determine the file type associated with that extension using the assoc command:

assoc .txt

📘 Example Output:

.txt=txtfile

This tells you that .txt files are associated with the file type identifier txtfile.
 

 
 

🛠 Step 2: Assign a Default Program Using ftype

Now that you have the file type, use ftype to set the default application. In the following example, we associate the Notepad++ editor with the .txt file type:

@echo off
ftype txtfile="C:\Program Files (x86)\Notepad++\notepad++.exe" "%1"

🔍 Explanation:

  • ftype txtfile=… sets the executable that will open files of type txtfile.
  • “%1” is a placeholder for the file being opened.

✅ After running this command, double-clicking any .txt file will launch it in Notepad++.
 

📄 Applies To More Than Just .TXT

You can apply the same method for any file extension, such as:

  • .pdf. → Adobe Reader or SumatraPDF
  • .svg. → Inkscape
  • .xml. → Visual Studio Code or Notepad++

 

 
 
🧠 Example: Associate .xml with VS Code

assoc .xml=xmlfile
ftype xmlfile="C:\Path\To\Code.exe" "%1"

⚠️ Considerations

  • You may need administrator privileges to change file associations system-wide.
  • This method does not work reliably for some modern file types due to Windows 10’s use of Per-User File Associations, especially post-Creators Update.
  • For enterprise-level deployments, consider using Group Policy, DISM, or PowerShell for robust control.

 

✅ Summary

Using assoc and ftype in a batch file allows you to automate setting default applications in Windows 10 for many common file types. While it’s not suitable for all use cases due to system restrictions, it’s a quick solution for many scripting or configuration scenarios.
 

🚀 Boost your productivity with the best AI toolsTry them

 

Leave a Reply

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