Replacing Notepad

From Notepad++ Wiki
Jump to: navigation, search
Make Notepad++ the Default TXT Editor

One might think it would be enough to replace the copy of Notepad.exe by a renamed Notepad++.exe. This may still work under Win9x/Me.

More recent versions of Windows are more careful about their integrity, and they consider Notepad.exe to be part of it. As a result, they won't let you replace Notepad.exe easily.

Googling for "replace notepad" may bring you procedures corresponding to your exact OS version - the service pack level may make a difference.

The basic idea is that, if all instances of the file "notepad.exe" are actually copies of notepad++.exe, then Windows will always launch your favorite text editor whenever a text editor is invoked (for instance, to view a readme file, edit the source of a web page, and such). But notepad++.exe requires configuration files, while the vintage notepad.exe doesn't. For this reason, you must have your configuration Files the %APPDATA%\Notepad++\ folder, since this is a central place for notepad++.exe to look at.

This idea will work on earlier versions of Windows (95/98/ME). It is too basic for two reasons:

  1. System restoration may replace your files by stock notepad.exe. A workaround would be to create a restore point right after replacing all files.
  2. Windows File Protection may prevent you from deleting notepad.exe, because it is considered a system component.

For a replacement method, you can check

Peer review and clean-up of duplicates or obsolete solutions is being requested

The following batch file comes from and is reported to work on Win2K and later - at least XP SP2:

@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
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
echo ----------------------------------------------------
echo  You did not specify a file, or file does not exist
echo ----------------------------------------------------

Windows Vista / 7

Windows Vista protects the interests of Microsoft (oops, users) much better, so that replacing a system component becomes harder. Here are links to Vista specific how-to's:

See also the short script on this thread.

Don't expect the changes to survive a service pack upgrade. You'll have to do it over again when this happens.

Adding a system restore point right after performing the replacement is not covered in the above material, and remains a good idea.

Non destructive approach

The following method is reported to also work, and does not involve replacing files.

This works for Windows NT/2K/XP/Server 2K3/Vista/Server 2K8/Win7 You must have Administrator privileges to write to the registry key. [The same author] wrote a complete tutorial and some sample scripts:

'// NOTES:
'// This affects all users.
'// This will prevent ANY executable named notepad.exe from running located anywhere on this computer!!
'// Save this text to your notepad++ folder as a text file named npp.vbs (some AV don't like vbs, get a different AV :-P )
'// 1)
'// Navigate to registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\
' // 2)
'// Add new subkey called notepad.exe
'// This step is what tells windows to use the notepad++ exe, to undo simply delete this key
'// 3)
'// Create new Sting Value called Debugger
'// 4)
'// Modify value and enter wscript.exe "path to npp.vbs" e.g. wscript.exe "C:\Program Files\Notepad++\npp.vbs"

Option Explicit
Dim sCmd, x
sCmd = """" & LeftB(WScript.ScriptFullName, LenB(WScript.ScriptFullName) - LenB(WScript.ScriptName)) & "notepad++.exe" & """ """
For x = 1 To WScript.Arguments.Count - 1
   sCmd = sCmd & WScript.Arguments(x) & " "
sCmd = sCmd & """"
CreateObject("WScript.Shell").Run sCmd, 1, True

The above is a modified form of the script which had been posted on the forum in 2009. It's been tested to work on Windows 7 (x86/x64) as well as Windows 8 (x64). Contact [1] or read this forum thread.

This batch was reported to work on Win7 64 bits:

@echo off 
set ReplaceNotepad=%cd%\notepad.exe
cd %windir% 

FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
takeown /f %%n
echo Y|cacls %%n /Grant %USERNAME%:F
copy %ReplaceNotePad% %%n
if errorlevel 1 call :whoops %%n

set ReplaceNotePad=
goto :exit

set OriginalNP=%1
set NPPath=!OriginalNotePad:~0,-12!

REM Fix if issue is that NotePad.EXE is in use
move !OriginalNP! !NPPPath!\notepad.original
copy %ReplaceNotePad% !OriginalNP!
if not errorlevel 1 goto :continue

REM Fix if issue is also directory permissions
takenown /f !NPPath!
echo Y|cacls !NPPath! /Grant %USERNAME%:F
move !OriginalNP! !NPPPath!\notepad.original
copy %ReplaceNotePad% !OriginalNP!
goto :continue

echo ***
echo *** After next reboot, delete the locked file
echo *** !NPPPath!\notepad.original
echo ***
goto :exit


( )

Another application to replace Notepac

Check this thread:


DISCLAIMER: The author doesn't have Windows Vista or later installed. The author is reasonably convinced that the procedures gathered on this page should work as advertised and were seemingly tested by others with success, but could not test them personally. As a consequence, no guarantee of final success or absence of undesirable side effects is being given thereby, and the featuring of the material on this page should not be construed as any sort of endorsement. Any liability of any kind will be rejected. Use the tips and tricks on this page AT YOUR OWN RISK.

Please report any enhancement to the procedures on this page that was found to be useful.