How do I make a batch file the default application for a file type
Solution 1
You can set it once via the control panel in Windows.
Solution 2
You can set it via the command line.
Let's assume your batch file is c:\temp\myBatch.bat
, and that the .SVG file type is already registered on the system as "svgfile" (you can run Assoc
from a command prompt to see the current association list to see what type .SVG is associated as).
- Open up an elevated command prompt.
- Type
Ftype svgfile=C:\temp\myBatch.bat %1
- Open up Explorer and double-click an SVG.
- It should run the batch with the SVG file's path and name fed to it as the first argument.
For more information check out this SU question: Programatically associate file extensions with application on Windows
Related videos on Youtube
Troy Daniels
Software engineer with a background in high-energy physics. Familiar with Java, Scala, C++, Python, Emacs Lisp, Rust and more.
Updated on September 18, 2022Comments
-
Troy Daniels almost 2 years
I am trying to associate .svg files with a batch file that runs squiggle from batik. When I right click on an svg and select
Open With
andChoose Default Program
, I get the usual window, which lists options that I don't want. I click onBrowse...
and get a file chooser.I navigate to the directory with the .bat file, which is visible. I click on the file and then
Open
. The file chooser closes, but the batch file does not appear in theOpen With
window.If I drag the svg file onto the bat file, it works. How do I make it the default association, so that I can just double click on the file?
-
Troy Daniels over 10 years
assoc .svg
says.svg=XMLSpy.svg
, as doesassoc | find "svg"
.ftype .svg=<path to batch file> %1
says `File type '.svg' not found or no open commadn associated with it. Double clicking still uses the old app. -
Troy Daniels over 10 yearsThis sort of worked. Initially, it did not recognize the batch file in the same way as going through the
Open With
dialog. I created a new file called test.bat and copied the contents of batik.bat (my desired file) to that. When I set test.bat as the default application, it now works. I'm not sure what the problem with my original file was. It had been saved with Unix end of lines rather than DOS, but changing that still did not fix the problem. -
Ƭᴇcʜιᴇ007 over 10 years@TroyDaniels You need to use the name shown by Assoc with FType. So it appears the command you should use would be
ftype XMLSpy.svg=<path to batch file> %1
. -
Ƭᴇcʜιᴇ007 over 10 yearshehe a random downvote for a perfectly usable answer. Gotta love those. ;)