系統在 C:\Windows 與 C:\Windows\System32 兩處都存在 notepad.exe,且檔案關聯分別註冊了這兩個路徑,導致右鍵「開啟方式」出現兩個相同的「記事本」選項。
@echo off
if exist "%systemroot%\notepad.exe" set Npath="%systemroot%\notepad.exe %1"
if not exist "%systemroot%\notepad.exe" set Npath="%systemroot%\system32\notepad.exe %1"
reg add "HKCR\txtfile\shell\open\command" /ve /d %Npath% /t REG_SZ /f
reg add "HKCR\Applications\notepad.exe\shell\open\command" /ve /d %Npath% /t REG_SZ /f
reg add "HKCR\SystemFileAssociations\text\shell\open\command" /ve /d %Npath% /t REG_SZ /f
修復記事本.bat,儲存類型選「所有檔案」。
批次檔透過判斷 %systemroot%\notepad.exe 是否存在,決定使用哪個路徑,並統一寫入三個關鍵的檔案關聯登錄鍵值,強制移除重複項。此法不需刪除實體檔案,安全且有效。