Replacing Notepad with Notepad2 in Windows 7 & Vista

by Ivan Hamilton 1/13/2010 6:48:00 PM

Standard Notepad Just Isn't Enough

For a technical user like me, Windows build in Notepad.exe sucks. It's better than nothing, but it's missing a stack of features:

  • line numbers ("status bar")
  • line numbers (it's worth mentioning twice)
  • line ending LF (Unix), CR/LF (Windows) & CR (Mac) handling
  • whitespace display
  • line ending display
  • regular expressions in search & replace
  • adjustable tab width

Don't use it then? I don't. I use Notepad2. Unfortunately, the standard Notepad.exe in Windows is embedded in a million different places - "Open With...",  open ".txt" files, edit ".bat" files, edit SQL scripts, view HTML source, and many more. Sure, you could try a search and replace excercise in the registry, but you'll probably install a new product that will try and utilise the original Notepad. Simply copy Notepad2.exe over Notepad.exe? The file protection mechanisms in Windows will automatically switch back to the original. Replace the protected version? It's possible if, a little tricky, but a future service pack or hotfix may simply overwrite it. What we need is EXE redirection.

Image File Execution Options 

Windows offers a neat way to automatically start a process within a debugger. Before execution, the Windows CreateProcess function checks for a registry key at "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\filename.exe". If that key has a string value named "debugger", then that value is executed instead with the existing command line added to the end (this could be [notepad] or ["C:\Windows\system32\notepad.exe"]). This means instead of "notepad hosts.txt", it will execute "debugger.exe notepad hosts.txt". So, you could run a substitute executable as long as you can get the new executable to ignore the first parameter. Notepad2 4.0.24 has introduced the "/z" switch, which means "ignore the next parameter" (this also exists in Programmer's Notepad) just for this purpose.

Configuring for Notepad Replacement

Start a command prompt (cmd.exe) as Administrator, and execute the following (replacing "C:\Program Files (x86)\Notepad2\Notepad2.exe" with the full path to your Notepad2 executable):

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v "Debugger" /t REG_SZ /d "\"C:\Program Files (x86)\Notepad2\Notepad2.exe\" /n /f \"^%LOCALAPPDATA^%\Notepad2.ini\" /z" /f 

Command line text Explaination 
reg the registry editing tool
add add the value
"HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe"  the key we're setting a value on
/v "Debugger" name of the value
/t REG_SZ type of the value (string)
/d the data to assign follows
" start of quotes around the data
\"C:\Program Files (x86)\Notepad2\Notepad2.exe\" The "debugger" executable to run (quotes are escaped with backslashes).
Change this to the full path to your Notepad2 executable (I'm on a x64 system).
/f \"^%LOCALAPPDATA^%\Notepad2.ini\" Notepad2 will use config file in user's profile directory (percent signs are escaped with carets)
/n Always open a new Notepad2 window
/z Notepad2 will ignore the next parameter (will always be the original Notepad.exe name)
" end of quotes around the data
/f forces reg.exe to overwrite any existing value

The first time you run it, the user specific config file won't exist (and won't automatically save on exit). If you want to keep your config settings, you'll need to explicitly save settings (F7) once, and from then on your settings will be saved.


Currently rated 3.0 by 22 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Powered by BlogEngine.NET
Original theme by Mads Kristensen

About the author

Name of author Ivan Hamilton
"My inner nerd can beat up your inner nerd."

E-mail me Send mail



<<  October 2021  >>

View posts in large calendar

Recent comments





    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2021

    Sign in