8

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.

12

6 Answers 6

4
+50

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).

7
  • This replacer batch file method works a treat. Thanks! But, could you tell me what you're doing with NotepadTempVar? You seem to be defining it, and then keep checking whether it's defined... Also, I advise removing your line about using 'Notepad Replacer'. It's closed source and I don't like installing that on my system as I can't be sure what it does. I will probably write something similar to that in future, but make it open source.
    – Jez
    Feb 29, 2012 at 23:18
  • @Jez I'm using NotepadTempVar in the first START line. I mentioned 'Notepad Replacer' for others' sake (I did mention you can skip trying it if you have reasons to avoid it such as being "closed source".) My batch file went through a LOT of changes and testing to come up with this current version. Initially I thought I could just throw in an EditPad.exe "%2" but it never worked. I came up with a much longer batch file to take care of the problem, but even that didn't work for some situations. Then slowly modifying and testing, I came up with this final version.
    – ADTC
    Mar 1, 2012 at 9:16
  • @Jez a little bit more about NotepadTempVar. It first takes the complete set of command line arguments. The second and third lines will remove the known paths of the system notepad.exe from NotepadTempVar. The reason why they (and other lines) have to check whether NotepadTempVar is defined is because if any of the SET operations receive an empty value to put in NotepadTempVar, it will become undefined, causing the next lines to work incorrectly (I have tested this already. Doing the removal of known path of notepad.exe on an undefined variable will give undesirable effects).
    – ADTC
    Mar 1, 2012 at 9:31
  • The last IF DEFINED ensures your EditPad doesn't behave incorrectly when the final value of NotepadTempVar is empty. (Notepad2 will automatically open the Open dialog when an empty string "" is passed in as the file name. I put in the check so that such things don't happen to anyone using my batch file, regardless of the replacement software they want to use.) This batch file also ensures paths with 2+ consecutive spaces don't break (my longer method failed). PS: I heard EditPad has an option to replace Notepad in its Config menu. Have you tried to find and use that first?
    – ADTC
    Mar 1, 2012 at 9:37
  • 1
    @Jez I have ensured my batch file will not fail when notepad.exe is opened directly (through Start Menu shortcut, or even by going into Windows/System32 directory and double-clicking on it). That was one of the tests I did. The IF DEFINED checks are actually for that, and to safeguard the batch file against any possible instance of an undefined NotepadTempVar. So that the proper commands are executed when the NotepadTempVar variables gets undefined (due to empty value being set to it using SET command). Hope it's clear :)
    – ADTC
    Mar 1, 2012 at 10:01
3

Use the Image File Execution Options registry key.

  • Open regedit.exe as Administrator.
  • Navigate to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
  • Create a new key (folder) named notepad.exe
  • Create a new REG_SZ value named Debugger and set its value to your path to the Editpad.exe executable.

Done. This doesn't require modifying or removing the system's notepad.exe, but no matter how a program attempts to run it (just try double clicking the program from Explorer yourself), it will run EditPad.

If you're on 64-bit Windows and attempting to use a 32-bit program, make your changes in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\ CurrentVersion\Image File Execution Options instead. (This info found on the Notepad2 - Replacing Windows Notepad page.)

6
  • 1
    Well, that does change things, but instead it now gives me a different error. :-) "The data area passed to a system call is too small."
    – Jez
    Feb 20, 2012 at 16:31
  • Check my edit. If EditPad is a 32-bit app, you might need to make the changes in a different registry key. Also of note, you can pass command line parameters as well if desired.
    – afrazier
    Feb 20, 2012 at 17:08
  • Putting it in the registry inside that Wow6432Node path still doesn't work. :-( I still get the same error.
    – Jez
    Feb 22, 2012 at 14:46
  • I can only think of 2 things: 1. If your path to EditPad contains spaces (e.g., "Program Files"), is the full path to the executable quoted in the registry? 2. There's some sort of subtle bug in EditPad. However, I just tested the demo of EditPad Pro in an XP VM and it worked for me. (Given, that's 32-bit XP vs. 64-bit 7, but 32-bit Notepad2.exe works on my 64-bit Win 7 system as well as the 64-bit Notepad2.exe does for the same purpose.)
    – afrazier
    Feb 24, 2012 at 15:00
  • 2
    afrazier's answer is how Notepad2 officially "replaces" Notepad with itself during installation, without actually replacing the Notepad executable file notepad.exe. However, Notepad2 has a /z command line argument which avoids opening the original Notepad's executable file (notepad.exe) as editable text in Notepad2 (since the Windows' Debugger system will pass it to Notepad2). Unless EditPad has some similar argument that can make it ignore the passed in notepad.exe you won't be able to correctly use afrazier's answer.
    – ADTC
    Feb 26, 2012 at 15:31
2

I've done this on my computer using Notepad Replacer. It doesn't actually replace any files, but it does cause anything notepad would have done to use whatever program you choose. I haven't seen the original notepad since I installed it. The uninstall will also revert everything back easily.

7
  • @Jez This should actually work and also take care of the problem I mentioned in my previous long comment. Let me know if it doesn't, coz I have another idea for you to try.
    – ADTC
    Feb 26, 2012 at 15:47
  • @ADTC Please post your other idea as an answer.
    – Jez
    Feb 26, 2012 at 22:44
  • Hmm ok @Jez. Btw, I hope you restored the original Windows Notepad (through the error message or by undoing your batch file change) before trying the Notepad Replacer here. If not, Windows is going to keep pestering you even if you try Notepad Replacer.
    – ADTC
    Feb 27, 2012 at 8:13
  • +1 - Good find that should allow Notepad to be replaced with any editor!
    – afrazier
    Feb 27, 2012 at 15:45
  • 1
    @Jez it's done. I had to test a lot to get the batch file to work correctly in all situations, which is why I took so long to prepare the answer.
    – ADTC
    Feb 27, 2012 at 21:02
1

I guess you also need to replace the notepad.exe file in %WINDIR%\winsxs\Backup but even this might not work properly - this has to do with Windows Resource Protection.

0

Simply run the batch file in the administrator mode.

  1. Right click on the batch file
  2. Select "Run as administrator"
  3. Proceed with the installation

If you have already executed this script before than most probably it won't work immediately and you will need to delete notepad.original.exe from %SystemRoot% and %SystemRoot%\System32:

rm %SystemRoot%\notepad.original.exe
rm %SystemRoot%\System32\notepad.original.exe

Remember that you also need to run this in the administrator mode, so copy above lines into a file and proceed with the same instructions as for the original batch file above.

2
  • I did run it in administrator mode. How would deleting the .original files help?
    – Jez
    Feb 20, 2012 at 15:45
  • I have first tried it in non-admin mode and it has failed, but created .original files. Later when running in the admin mode it didn't work since .original files already existed. But as soon as I have deleted them - the script worked. I do not know why it doesn't work for you - I am also using Win7 64-bit. Feb 20, 2012 at 15:50
0

You wrote:

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."

notepad.exe is a Windows protected file that's why it's a bit tricky to replace it...

Here's a manual solution from the HowTo Geek web site: How To Replace Notepad in Windows 7

http://www.howtogeek.com/howto/12617/how-to-replace-notepad-in-windows-7/

Another option may be to use the Sysinternals command line utility PsExec in your batchfile with the following switches

...PsExec.exe" -i -d -s...

PsExec: http://technet.microsoft.com/en-us/sysinternals/bb897553

Hope this help. Let us know.

3
  • With regard to the HowTo Geek website, unfortunately Windows 7 idiotically refuses to run executables in the system32 directory for which "the publisher could not be verified", which seems to apply for my editpad.exe. If I try to run it in the system32 directory, I get the "Your copy of NOTEPAD.EXE appears to have been damaged..." error.
    – Jez
    Feb 27, 2012 at 16:46
  • Check this article: Windows: Disable “Publisher Could Not Be Verified” Messages technipages.com/… Is it a solution for you? I hope so! :)
    – climenole
    Feb 27, 2012 at 17:05
  • @Jez Btw somebody commented on that HowToGeek article that "I’ve been using EditPad for years now, and it can be set to replace Windows Notepad with no hassle – just by checking an option in its config menu." Did you check for such an option in its config menu?
    – ADTC
    Feb 27, 2012 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .