My Software Notes

Useful things I discover

Archive for July 2012

Replacing Notepad.exe

leave a comment »

You want to use your favorite text editor rather than Notepad.  It seems like you could just rename the exe of your favorite to “notepad.exe” and drop it into the Windows directory.  But it won’t work.

First your favorite text editor may not be composed of just one exe file.  Second Windows regards Notepad as part of its installation and Windows Protection will overwrite your text editor at some point.

But there is a way to do it and here it is:

(I’m using Notepad++ as my example text editor. You can alter the various paths and file names to suite your own situation.)

1. Create a cmd file containing these two lines:

@echo off 
start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" %2 %3 %4 %5 %6

Save it in the Notepad++ folder. Call it npplauncher.cmd

2. Open regedit and navigate to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\

3. Add a key under “Image File Execution Options”. Name the key “notepad.exe”.

4. To the key add a string value with the name “Debugger” and the value “C:\Program Files (x86)\Notepad++\npplauncher.cmd”.

That should do it.  Now just double-click a txt file or type “notepad myfile.txt” at the command line and your text editor will open instead of Notepad.

FAQs:

Q: Why do we drop %1 in the cmd file? 

The command line you use when you attempt to run your text editor will look something like “notepad myfile.txt”.  This entire command line is passed to npplauncher.cmd and the first parameter will be “notepad”, which you don’t want to open in your text editor, so we drop it.

Q: Why do you have an empty string as the first parameter to the start command?

If the first parameter to start has quotes around it then start treats it as the title of the window that it will open.  If you omit the empty string then “C:\Program Files (x86)\Notepad++\notepad++.exe” will be treated as a title and not as a program to run.  Here is where I found this: http://stackoverflow.com/questions/154075/using-the-dos-start-command-with-parameters-passed-to-the-started-program

Q: Why do you put the editor’s name into the “Debugger” string value?

It launches the application you’ve named as the debugger for the application named in the key.  I.e., “C:\Program Files (x86)\Notepad++\notepad++.exe” is regarded as the debugger for “notepad.exe”.  For a much better explanation see this: Replacing Windows Applications – the Safe Way.

Q: Why do I need the npplauncher.cmd file?

You can get around it if your editor has a way for you to ignore the first parameter.  The only reason for the cmd file is to ignore that first parameter.  See the “Replacing Windows Applications – the Safe Way” article I linked to ealier for details.  I guess another reason for the cmd would be if there are other things you want to do to the command line before passing it on to the text editor, e.g., for Notepad++ you could add the -multiInst parameter.

Q: Why do you have %2 through %6 in your cmd file?

I just decided to pass up to 5 parameters.  If you want more then add more.  If you want to get really fancy then you can probably find some crazy DOS command that will allow you to pass the entire command line minus the first parameter.

Q: I use Notepad++ and I want to use the -multiInst parameter.  How do I do that?

Just put -multiInst before the %2 in the cmd file.

start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" -multiInst %2 %3 %4 %5 %6

Summary

So that’s it.  Pretty easy really, once you know.

Other references:

http://sourceforge.net/projects/notepad-plus/forums/forum/331753/topic/3435863

 

Written by gsdwriter

July 11, 2012 at 3:11 pm