首页 > 解决方案 > To associate file extension with specific program

问题描述

I'm trying to associate specific file extensions with specific programs. For example, when I press Enter on .txt file, it should be opened in Sublime Text. Or may be in Vim. Or may be in Chrome.

I need to achieve it with command line. At first glance, it could be achieved in the following way:

FTYPE txtfile=C:\Program Files\Google\Chrome\Application\chrome.exe "%1"
ASSOC .txt=txtfile

But actually it does nothing for me: .txt files opens in Sublime Text, not in browser.

What I'm doing wrong?

标签: windowsbatch-filecmdfile-association

解决方案


I would expect the following to function as intended, despite my reluctance to advise it.

@"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\.txt" /VE /D "txtfile" /F > NUL
@"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\txtfile" /VE /D "Text Document" /F > NUL
@"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\txtfile\shell\open\command" /VE /D "\"%ProgramFiles%\Google\Chrome\Application\chrome.exe\" \"%%L\"" /F > NUL

"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\.txt" /VE /D "txtfile" /F > NUL
"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\txtfile" /VE /D "Text Document" /F > NUL
"%__AppDir__%reg.exe" Add "HKCU\Software\Classes\txtfile\shell\open\command" /VE /D "\"%ProgramFiles%\Google\Chrome\Application\chrome.exe\" \"%L\"" /F > NUL

推荐阅读