Skip to content

Replacing Notepad with Notepad++ using Image File Execution Options

Last updated on February 12, 2017

I’ve been irritated for sometime by the apparent lack of desktop real estate when working on many webdev tasks in Windows 7. It may have been the same in WinXP, but honestly it’s been so long I don’t remember. While I don’t profess to be a greybeard or anything like that, I’ve yet to find an IDE that makes my life easier when working on PHP, JS, and CSS especially when most of the time I’m not doing much more than quick fixes.

For the longest time my solution to my conundrum has been to use Notepad2, actually a modified version of it Notepad2 w/ code folding. What I’ve noticed, and what’s prompted me to move away from Notepad2 is that the lack of tabs means that many times I’ll have a half dozen windows open as I try and find and fix whatever craziness I’m working on, and that was a large part of my lack of screen real estate.

My solution was, rather drastically, to dump Notepad2 and move to Notepad++. Unfortunately that brings it’s own issues to the table. The big one, and what prompted this post, is that Notepad++ doesn’t cleanly replace notepad completely. What you can do is have it take over the file extensions for the files you want it to edit. That of course brings it’s own set of problem, namely now your file types all read “Notepad++ file” instead of something more useful like what it actually is.

The best non-destructive way to replace Notepad is to use the Image File Execution Options hook in the registry to have windows launch Notepad++ instead of Notepad. The trick, unlike Notepad2 is that Notepad++ wasn’t apparently designed to be pluged in this way directly. There is a nice, article in the Notepad++ wiki on replacing notepad and that’s what brings me to this post.

The problem I’ve run into is that following their instructions it’s impossible to edit files with either spaces in their name or spaces in the path name. The procedure is the same as outlined by the Notepad++ wiki, only there’s a slight modification to the script that’s used. The the modified script is shown below.

Option Explicit
Dim sCmd, x, arg
sCmd = """" & LeftB(WScript.ScriptFullName, LenB(WScript.ScriptFullName) _
		- LenB(WScript.ScriptName)) _
		& "notepad++.exe" & """"
For x = 1 To WScript.Arguments.Count - 1
	arg = arg & " " & WScript.Arguments( x )
Next
sCmd = sCmd & " """ & trim(arg) & """"
CreateObject("WScript.Shell").Run sCmd, 1, True
WScript.Quit

Note: I’ve split the first sCmd line to make it fit on the page, the splits should work as well in the actual vbs file.

The key here is that script needs to collapse the file name arguments into a single quoted argument, which is what the for loop does now.

Published inWin 7

5 Comments

  1. Federico

    Thanks for the script! One small suggestion: when starting notepad without arguments (for example from the start menu), your script prompt the user to create a file that does not exist. This is because sCmd has the additional “””” argument when Arguments.Count = 1. I suggest you modify it to this:
    [code]
    Option Explicit
    Dim sCmd, x, arg
    sCmd = “””” & LeftB(WScript.ScriptFullName, LenB(WScript.ScriptFullName) – LenB(WScript.ScriptName)) & “notepad++.exe” & “”””
    If WScript.Arguments.Count > 1 Then
    For x = 1 To WScript.Arguments.Count – 1
    arg = arg & ” ” & WScript.Arguments( x )
    Next
    sCmd = sCmd & ” “”” & trim(arg) & “”””
    End If
    CreateObject(“WScript.Shell”).Run sCmd, 1, True
    WScript.Quit
    [/code]

  2. Anonymous

    Instead of a registry file, use a batch file. This way folder paths don’t need to be edited. Just create notepadpp.bat in the same folder and insert the following:

    reg add “HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe” /v “Debugger” /t REG_SZ /d “wscript \”C:\Portable Programs\Notepad++\notepadpp.vbs\”” /f
    pause

    Run as administrator, obviously. If I were a better coder, I could include an option within the same batch file to restore as well.

  3. the internet

    Thanks so much for all the above. This is a very tidy solution to the problem. 🙂

Comments are closed.