T.Todua
T.Todua

Reputation: 56351

File association using CMD

What are ways to associate file from cmd? For example,I want .txt file extension to associate with a typical program, through command prompt? what is the correct file association cmd command?

Upvotes: 3

Views: 4669

Answers (3)

Massimo Boaron
Massimo Boaron

Reputation: 1

The previous suggested solutions are unnecessarily complicated and risky. Just right click on the file, click "Open with" and indicate the App you prefer (flag for permanent replacement). Windows does all this automatically and without risk.

Upvotes: 0

T.Todua
T.Todua

Reputation: 56351

File association with COMMAND PROMPT (using .bat file):

REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command"     /v ""     /t REG_SZ     /d "\"C:\Program Files\\Notepad++\\notepad++.exe\" \"%%1\""       /f
::or use --------------->  REG ADD "HKEY_CLASSES_ROOT\txtfile\shell\open\command"                        /v ""     /t REG_SZ     /d "\"C:\Program Files\\Notepad++\\notepad++.exe\" \"%%1\""       /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt"                 /v "Application"   /t REG_SZ     /d "notepad++.exe"      /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList"    /v "g"             /t REG_SZ     /d "notepad++.exe"      /f

ftype txtfile="C:\Program Files\Notepad++\notepad++.exe" "%%1"      
assoc .txt=txtfile

NOTE! If typing directly in CMD(instead of .bat) then use single % (instead of double %%) and single \ (instead of double \)

Upvotes: 1

JosefZ
JosefZ

Reputation: 30113

One needs to use ftype and assoc commands as follows (and note that sequence matters):

ftype txtfile="C:\Program Files (x86)\PSPad editor\PSPad.exe" "%1"
assoc .log=txtfile
assoc .txt=txtfile
assoc .wtx=txtfile

or

ftype TIFImage.Document="C:\Program Files\MSPVIEW.exe" "%1"
assoc .tif=TIFImage.Document
assoc .tiff=TIFImage.Document

Note that I haven't MSPVIEW.exe installed so I can't approve your ftype assignment rightness. In my Windows ftype TIFImage.Document command output is as follows:

TIFImage.Document=%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1

Upvotes: 5

Related Questions