Windows 7 – Replace Notepad.exe

notepadwindows 7

OK, I really really want to replace the default notepad.exe in Windows 7 with Editpad (yes, I want to replace the actual executable, and no I don't want to use something like Notepad2, so please don't suggest that). I used the following batch script which has worked for me before:

@echo off
TITLE EditPad Install Script for Complete Windows Vista and 7 Notepad Replacement
echo.
echo EditPad Install Script for Complete Windows Vista and 7 Notepad Replacement
echo Version 2.0
echo.
echo Confirm to apply? (Press Ctrl-C and answer Y to terminate)
pause
echo.
echo.

if exist %SystemRoot%\notepad.original.exe goto exist_editpad_already
if exist %SystemRoot%\System32\notepad.original.exe goto exist_editpad_already
takeown /f %SystemRoot%\notepad.exe
takeown /f %SystemRoot%\System32\notepad.exe
icacls %SystemRoot%\notepad.exe /grant "%USERNAME%":f
icacls %SystemRoot%\System32\notepad.exe /grant "%USERNAME%":f
IF EXIST %SystemRoot%\SysWOW64 (bcdedit.exe -set loadoptions "DDISABLE_INTEGRITY_CHECKS")
copy %SystemRoot%\notepad.exe %SystemRoot%\notepad.original.exe
copy %SystemRoot%\System32\notepad.exe %SystemRoot%\System32\notepad.original.exe
echo.
echo Original notepad.exe has been renamed to "notepad.original.exe" in its original folder.
echo.
echo Overwriting %SystemRoot%\notepad.exe with "%~dp0\EditPad.exe"
copy "%~dp0\EditPad.exe" %SystemRoot%\notepad.exe /y
echo Overwriting %SystemRoot%\System32\notepad.exe with "%~dp0\EditPad.exe"
copy "%~dp0\EditPad.exe" %SystemRoot%\System32\notepad.exe /y
echo.
echo EditPad installation is completed.
echo If no error occurred, EditPad will now replace all Notepad functions.
echo.
pause
goto eof

:exist_editpad_already
echo.
echo INSTALLED EditPad ALREADY! (notepad.original.exe exists in windows or windows system32)
echo.
pause
goto eof

:eof

This script did replace notepad.exe with the Editpad executable, but now if I try and open a text file, I get the error "Your copy of NOTEPAD.EXE appears to have been damaged. Please try reinstalling it from the original setup package."

I am using Windows 7 64 bit. What could I do to force Windows to let me use Editpad as my notepad.exe without giving me this stupid error message?

UPDATE:
I think I have some more information that may help things a bit. The problem seems to be with me running editpad.exe at all inside the system32 directory. If I substitute various other exe files for system32\notepad.exe they run fine, but when I try to run editpad.exe inside that directory, Windows 7 gives me a popup dialog: "The publisher could not be verified. Are you sure you want to run this software?" If I click Run, I get the 'file is damaged' error – but ONLY if I'm running it inside the system32 directory. I need to find a way to get this exe running inside the system32 directory.

Best Answer

My idea is to create a supporter app that can piggyback on the Image File Execution registry entries to run EditPad correctly.

Note: You will have to restore your original Windows Notepad first, either through the error message that pops up, or by undoing the changes you made. Otherwise Windows may keep pestering you with the error message no matter what you try.

Tip: Notepad Replacer suggested by Dracs does something similar to what is below automatically. Try that first, unless you have reasons to avoid it such as the application being closed source. In which case, you can use the method below:

  1. Create a batch file with the following code. The batch file could be named Replacer.bat for example, and it could be placed anywhere such as EditPad's installation folder. (I assume EditPad is installed in the path given. If not, please change it.)

    SET NotepadTempVar=%*
    IF DEFINED NotepadTempVar SET NotepadTempVar=%NotepadTempVar:"C:\Windows\System32\notepad.exe"=%
    IF DEFINED NotepadTempVar SET NotepadTempVar=%NotepadTempVar:"C:\Windows\notepad.exe"=%
    IF DEFINED NotepadTempVar (
        FOR /F "tokens=*" %%A IN ("%NotepadTempVar%") DO SET NotepadTempVar=%%A
    )
    IF DEFINED NotepadTempVar (
        START "" "C:\Program Files\EditPad\EditPad.exe" "%NotepadTempVar%"
    ) ELSE (
        START "" "C:\Program Files\EditPad\EditPad.exe"
    )
    
    • CAUTION! It is necessary to have the empty string "" after START command, otherwise your system can go into an infinite loop of creating new Command Prompt windows.
    • You may have to verify the paths of the original Notepad in second and third lines to reflect your system. I found the paths to be same in both 32-bit and 64-bit Windows. The paths are case-insensitive but be careful to keep the quote marks around them.
    • On 64-bit Windows, you may need to add this extra line between the second and third lines:

      IF DEFINED NotepadTempVar SET NotepadTempVar=%NotepadTempVar:"C:\Windows\SysWOW64\notepad.exe"=%
      


  2. (optional) Use Batch To Exe Converter to compile the batch file to an executable program. Choose the "Invisible application" option.

    • If you do not wish to use Batch To Exe Converter, you may use another solution, or you may use the batch file itself for the following steps, instead of the compiled EXE file. However, if you use the batch file itself, you will see a momentary flashing of a command window before EditPad opens.

  3. Open Registry Editor by opening Start menu and searching for regedit (or using the Run command to run regedit).

  4. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options

  5. If a key (folder in left pane) named notepad.exe does not exist inside Image File Execution Options, click Edit > New > Key and type notepad.exe as the new key's name. If it already exists, simply navigate to it.

  6. If an entry named Debugger (type REG_SZ) does not exist in the notepad.exe key (on right side), click Edit > New > String Value and type Debugger as the new entry's name.

  7. Double-click the entry named Debugger and enter the full qualified location and name of the EXE file generated by Batch To Exe Converter or the batch file if you did not use a compiler. Enclose the location in quotation marks.

    • For example, assuming you have stored the batch file in EditPad's program folder, the value of Debugger entry could be "C:\Program Files\EditPad\Replacer.bat" or "C:\Program Files\EditPad\Replacer.exe" where Replacer.bat is the batch file and Replacer.exe is the compiled EXE file obtained in step 2, if any.

  8. Test the setup by:

    • Opening Windows Notepad from Start Menu. EditPad should open instead.
    • Double-clicking on a text file or any file that's associated with Windows Notepad.
    • Testing other means you know should normally open Windows Notepad. They will very likely open EditPad instead.

If there are any problems, your paths in the batch file created in step 1 may not be correct. All other steps should be OK without any problem if you followed them correctly. Just verify and correct the paths in the batch file (and recompile EXE if needed).

Related Question