Cerca de um ano atrás, escrevi um pequeno script em lote para lidar com esse problema de associação de arquivos de texto. Eu trabalho na maioria das vezes, mas às vezes (após a atualização do windows aplicada, por exemplo) a associação irá restaurar para o padrão, caso isso ocorra, vou rodar novamente o lote.
Eu escolhi meus 3 editores de texto favoritos no script em lote.
-
Notepad2 (ou Notepad2-mod ) para arquivos de texto leves. Diretório de instalação padrão:
%SystemRoot%
-
Notepad ++ para .sql .sh. Diretório de instalação padrão:
%ProgramFiles%\Notepad++
-
EditPlus para a maioria dos arquivos de texto da linguagem de programação. Diretório de instalação padrão:
%ProgramFiles%\EditPlus 3
Você precisa alterá-los para seu editor de texto favorito e precisa alterar os tipos de arquivo correspondentes para o seu.
@echo off
echo --------------------------------------------------------------------------
echo Windows text file association
echo --------------------------------------------------------------------------
REM ----------------------------------------------------------------------------
REM References
REM ----------------------------------------------------------------------------
REM Windows file associations
REM http://vim.wikia.com/wiki/Windows_file_associations
REM
REM Managing Files from the Command Line - Assoc and Ftype
REM http://commandwindows.com/assoc.htm
REM
REM Adding Associations
REM http://winbeginners.com/articles/associations3.htm
REM
REM CClean scan result show some error about registry HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
REM
REM http://superuser.com/questions/212848/how-change-file-association
REM
REM Windows registry information for advanced users
REM http://support.microsoft.com/kb/256986
REM ----------------------------------------------------------------------------
REM setlocal enabledelayedexpansion
set PROGRAM_DIR=%%ProgramFiles%%
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGRAM_DIR=%%ProgramFiles(x86)%%
REM notepad2
set NOTEPAD2=%%SystemRoot%%\notepad2.exe
REM Notepad++
set NPP=%PROGRAM_DIR%\Notepad++\notepad++.exe
if not exist "%ProgramFiles%\Notepad++\notepad++.exe" set NPP=%NOTEPAD2%
REM EditPlus
set EDITPLUS=%PROGRAM_DIR%\EditPlus 3\editplus.exe
if not exist "%ProgramFiles%\EditPlus 3\editplus.exe" set EDITPLUS=%NPP%
REM ----------------------------------------------------------------------------
REM Text file
REM ----------------------------------------------------------------------------
assoc .csv=txtfile
REM CueSheet
assoc .cue=txtfile
REM ----------------------------------------------------------------------------
REM C/C++
REM ----------------------------------------------------------------------------
assoc .h=SourceCode.C
assoc .c=SourceCode.C
assoc .hpp=SourceCode.C
assoc .cpp=SourceCode.C
assoc .cxx=SourceCode.C
assoc .rc=SourceCode.C
assoc .inc=SourceCode.C
REM AMXModX Script
assoc .sma=SourceCode.C
REM ----------------------------------------------------------------------------
REM Java
REM ----------------------------------------------------------------------------
assoc .java=SourceCode.Java
REM BeanShell
assoc .bsh=SourceCode.Java
REM ZK Script
assoc .zs=SourceCode.Java
REM ----------------------------------------------------------------------------
REM C#
REM ----------------------------------------------------------------------------
assoc .cs=SourceCode.CSharp
REM ----------------------------------------------------------------------------
REM SQL
REM ----------------------------------------------------------------------------
assoc .sql=sqlfile
REM ----------------------------------------------------------------------------
REM Web
REM ----------------------------------------------------------------------------
REM assoc .css=CSSfile
REM assoc .html=htmlfile
REM assoc .htm=htmlfile
assoc .shtml=htmlfile
REM assoc .js=jsfile
assoc .htc=htcfile
assoc .zul=SourceCode.ZK.UI
assoc .zhtml=SourceCode.ZK.UI
assoc .jsp=SourceCode.JSP
assoc .jspx=SourceCode.JSP
assoc .php=SourceCode.PHP
assoc .asp=SourceCode.ASP
assoc .aspx=SourceCode.ASP
REM ----------------------------------------------------------------------------
REM Shell
REM ----------------------------------------------------------------------------
assoc .awk=SourceCode.Shell
assoc .sed=SourceCode.Shell
assoc .sh=SourceCode.Shell
assoc .ps=SourceCode.PowerShell
REM assoc .bat=batfile
REM assoc .cmd=cmdfile
REM 对于批处理文件,不修改默认关联,而仅仅修改“编辑”动作的关联
REM ----------------------------------------------------------------------------
REM Configuration
REM ----------------------------------------------------------------------------
REM assoc .ini=inifile
REM assoc .inf=inffile
assoc .cfg=cfgfile
assoc .conf=Configuration.POSIX
assoc .properties=Configuration.Java
assoc .svg=svgfile
REM reg add
REM ----------------------------------------------------------------------------
REM Misc
REM ----------------------------------------------------------------------------
REM assoc .dsn=ODBC.FileDSN
REM assoc .eml=Microsoft Internet Mail Message
REM assoc .hta=htafile
REM assoc .jnlp=JNLPFile
REM assoc .log=txtfile
assoc .m3u=m3ufile
REM assoc .mht=mhtmlfile
REM assoc .mhtml=mhtmlfile
REM assoc .nfo=MSInfo.Document
REM assoc .reg=regfile
REM assoc .rtf=rtffile
REM assoc .scp=txtfile
REM SELinux Targeted policy .te
assoc .te=txtfile
REM assoc .txt=txtfile
REM assoc .wsc=scriptletfile
REM assoc .WSF=WSFFile
REM assoc .WSH=WSHFile
REM assoc .wtx=txtfile
REM assoc .xaml=Windows.XamlDocument
REM assoc .xhtml=xhtmlfile
REM assoc .xml=xmlfile
call :np2_open txtfile inifile jsfile cfgfile Configuration.POSIX Configuration.Java
call :np2_edit batfile cmdfile jsfile WSFFile WSHFile regfile m3ufile ODBC.FileDSN "Microsoft Internet Mail Message"
call :ep_open cssfile xmlfile xslfile xsltfile SourceCode.C SourceCode.Java SourceCode.CSharp SourceCode.JSP SourceCode.PHP SourceCode.ASP SourceCode.ZK.UI
call :ep_edit xmlfile svgfile htmlfile xhtmlfile shtmlfile htafile htcfile rtffile JNLPFile
call :npp_open SourceCode.Shell SourceCode.PowerShell sqlfile
pause
goto :EOF
:np2_open
if "%~1"=="" goto :EOF
REM echo %NOTEPAD2% [Open] %1
ftype %1="%NOTEPAD2%" "%%1"
shift
goto np2_open
:np2_edit
if "%~1"=="" goto :EOF
echo %NOTEPAD2% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%NOTEPAD2%\" \"%%1\""
shift
goto np2_edit
:npp_open
if "%~1"=="" goto :EOF
REM echo %NPP% [Open] %1
ftype %1="%NPP%" "%%1"
shift
goto npp_open
:npp_edit
if "%1"=="" goto :EOF
echo %NPP% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%NPP%\" \"%%1\""
shift
goto npp_edit
:ep_open
if "%~1"=="" goto :EOF
REM echo %EDITPLUS% [Open] %1
ftype %1="%EDITPLUS%" "%%1"
shift
goto ep_open
:ep_edit
if "%~1"=="" goto :EOF
echo %EDITPLUS% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%EDITPLUS%\" \"%%1\""
shift
goto ep_edit