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:
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
||the registry editing tool
||add the value
|"HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe"
||the key we're setting a value on
||name of the value
||type of the value (string)
||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).
||Notepad2 will use config file in user's profile directory (percent signs are escaped with carets)
||Always open a new Notepad2 window
||Notepad2 will ignore the next parameter (will always be the original Notepad.exe name)
||end of quotes around the data
||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.