Tuesday, April 20, 2004

Replace Notepad (Windows XP/2000 and later)

Edit - 30-Mar-2005: Fixed issues if backup version of notepad was in another folder, or SP2 was applied (C:\I386 or %windir%\ServicePackFiles\i386\)

The following batch script will allow you to replace notepad with a text edtor of your choice (will replace it for all users). Drag the file you wish to replace it with onto the batch script to do the replacement. You will probably get a warning about replacing a critical system file - you can ignore this. For it to work you need admin rights. To restore notepad, just double-click on the batch file. The use of this script is AT YOUR OWN RISK.

@echo off
REM This will replace Windows notepad with the program of your choice
REM The use of this script is AT YOUR OWN RISK.
REM filename to backup to
SET backupto=oldnotepad.exe
REM get file from parameter supplied
SET file=%1
REM if backup file exists, end the script
IF EXIST %windir%\system32\dllcache\%backupto% GOTO alreadyreplaced
REM If you do not specify a parameter, end the script
REM brackets are needed as spaces are ignored
IF (%file%) == () GOTO nofile
REM If source file does not exist, the replacement can not be made
IF NOT EXIST %file% GOTO nofile
attrib -r -h -s %windir%\system32\dllcache
ren %windir%\system32\dllcache\notepad.exe %backupto%
attrib +r +h +s %windir%\system32\dllcache
del %windir%\notepad.exe
copy /Y %file% %windir%\notepad.exe
del %windir%\system32\notepad.exe
copy /Y %file% %windir%\system32\notepad.exe
REM other folders that may contain notepad
IF EXIST C:\I386\notepad.exe ren C:\I386\notepad.exe %backupto%
IF EXIST %windir%\ServicePackFiles\i386\notepad.exe ren %windir%\ServicePackFiles\i386\notepad.exe %backupto%
GOTO end
:alreadyreplaced
attrib -r -h -s %windir%\system32\dllcache
ren %windir%\system32\dllcache\%backupto% notepad.exe
attrib +r +h +s %windir%\system32\dllcache
REM deleting the other notepad files will cause WFP to replace with the one in the dll cache
del %windir%\system32\notepad.exe
del %windir%\notepad.exe
REM other folders that may contain notepad
IF EXIST C:\I386\%backupto% ren C:\I386\%backupto% notepad.exe
IF EXIST %windir%\ServicePackFiles\i386\%backupto% ren %windir%\ServicePackFiles\i386\%backupto% notepad.exe
echo ------------------------------------------------------
echo  Notepad has already been replaced, original restored
echo ------------------------------------------------------
GOTO end
:nofile
echo ----------------------------------------------------
echo  You did not specify a file, or file does not exist
echo ----------------------------------------------------
:end

Tested on Windows XP - but should work on 2000. May not work on Windows 95/98/ME.


Tags: ,