使用 CMD 进行文件关联

File association using CMD

cmd关联文件的方法有哪些? 例如,我希望通过命令提示符将 .txt 文件扩展名与典型程序相关联? 正确的文件关联 cmd 命令是什么?

需要使用 ftypeassoc 命令如下(注意顺序很重要):

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

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

请注意,我还没有 MSPVIEW.exe 安装,所以我无法批准您的 ftype 分配权。在my Windows ftype TIFImage.Document命令输出如下:

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

与 COMMAND PROMPT 的文件关联(使用 .bat 文件):

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

注意!如果直接在 CMD 中键入(而不是 .bat),则使用单个 %(而不是双 %%)和单个 \(而不是双 \)