FTYPE

Display or change the link between a FileType and an executable program.

Syntax
   FTYPE fileType=executable_path
   
   FTYPE

   FTYPE fileType

   FTYPE fileType=

Key
   fileType        : The type of file

   executable_path : The executable program including any command line parameters

File Types can be displayed in Windows Settings under:
Apps > Default apps > Choose default apps by file type

XML Registration.

Microsoft have changed how file associations work from Windows 8 /2012 onward to prevent malicious apps from changing file associations on the fly. It is no longer possible to use the registry or FTYPE for file association hijacking.

Microsoft blog post:

In Pre-Win 8, apps could set the default handler for a file type/protocol by manipulating the registry, this means you could easily have a script or a group policy manipulating the registry. However In Win 8, the registry changes are verified by a hash (unique per user and app) that detects tampering by apps. In the absence of a valid hash, we ignore the default in the registry. Microsoft have introduced a new Group Policy mechanism for declaring these defaults in Win 8 to accommodate this type of scenario...

The way Microsoft expect you to change this now is with an xml file applied through Group Policy. Instructions here.

The Settings pane will only display installed applications (FileTypes) and/or an option to install apps from the Windows store. There is no option to manually add a file association for a non-Windows store application.

Christoph Kolbicz has reverse engineered the hashing algorithm and created a tool called SetUserFTA to set the file type association on a single machine.

FTYPE can still be used to display registration entries from the registry, but those may not reflect changes made via Group Policy.

Here is a list of Common File Extensions and FileTypes.

Several FileTypes can be linked to the same executable application.

FTYPE filetype will display the current executable program for that file type e.g. FTYPE jpegfile.

FTYPE without any parameters will display all FileTypes and the executable program for each.

More than one file extension can be associated with the same File Type.
e.g. both the extension .JPG and the extension .JPEG can be associated with the File Type "jpegfile"

So the path is: File Extension >> File Type >> executable program
e.g. .TXT > txtfile >> \system32\NOTEPAD.EXE

The FileType should always be created before making a File Association with ASSOC

Defining command line parameters

It is almost always necessary to supply command line parameters so that when a document is opened not only is the relevant application loaded into memory but the document itself also loaded into the application. To make this happen the filename of the document must be passed back to the application.

Command line parameters are exactly like batch file parameters, %0 is the executable program and %1 will reference the document filename

so a simple command line might be:

MyApplication.exe "%1"

If any further parameters are required by the application they can be passed as %2, %3. To pass ALL parameters to an application use %*. To pass all the remaining parameters starting with the nth parameter, use %~n where n is between 2 and 9.

Switch between multiple applications

If you have multiple applications that use the same file extension, the ASSOC command can be used to switch the file extension between the different FileTypes. This does not remove the fileType for the other application, it will remain so you can easily switch back.

Delete a FileType

Specify executable_path=nothing and the FTYPE command will delete the executable_path for that FileType.
For example:
FTYPE htmlfile=

Backup FileTypes

FTYPE >backup_types.txt
ASSOC >backup_ext.txt

Restore FileTypes from a Backup

FOR /F "tokens=* delims=" %G IN (backup_types.txt) DO FTYPE %G
FOR /F "tokens=* delims=" %G IN (backup_ext.txt) DO ASSOC %G


This will recreate the CLASS id's in the registry at HKey_Classes_Root\.<file extension>
If you put the commands above in a batch file change the %G to be %%G

Use file associations at the command line

If you have a file association between .DOC and Word for Windows then at a command prompt you can open a document with any of the following commands:

Start "My Document.doc"
"Monthly Report.doc"
JULY.DOC


note that the file extension must be supplied for this to work

Errorlevels

When CMD Command Extensions are enabled (the default):
If the File Type Association could not be changed %ERRORLEVEL% = 1
If the File Type Association was successfully changed %ERRORLEVEL% = 0

FTYPE is an internal command.
If Command Extensions are disabled, the FTYPE command will not function.

Examples

The percent signs are doubled to escape them, because a single percent has a special meaning within a batch file.

@ECHO OFF
FTYPE pagemill.html=C:\PROGRA~1\Adobe\PAGEMI~1.0\PageMill.exe "%%1"
ASSOC .html=pagemill.html

FTYPE rtffile="C:\Program Files\Windows NT\Accessories\WORDPAD.EXE" "%%1"
ASSOC .rtf=rtffile

FTYPE word.rtf.8="%%ProgramFiles%%\Microsoft Office\Office\winword.exe" /n "%%1"
ASSOC .rtf=word.rtf.8

"True to type - Of a plant, or group of plants, which matches the accepted description of the cultivar to which it is assumed to belong"

Related commands:

ASSOC - Change file extension associations.
DISM /online /export-defaultappassociations
SetUserFTA - Utility to set the file type association.
Batch file to list the application associated with a file extension.
DirectInvoke - Register MIME Types for direct invocation from a URL (legacy Internet Explorer feature) /o "%u"
Raymond Chen - Why do my PDF file associations get reset every time I restart?


 
Copyright © 1999-2022 SS64.com
Some rights reserved