Windows 7 script (works)

Lexxter
2010-05-01
2012-11-13
  • Lexxter

    Lexxter - 2010-05-01

    This script automates replacing notepad with notepad++ in Win7 32/64. 

    Get notepad.exe from the official site here: Notepad Replacement
    Create a text file with notepad in the same folder where you saved notepad.exe, paste this script into notepad, save it, and run it.   Make sure to save the text file as .bat or .cmd - not .txt.

    You will probably need admin rights to do this.

    @echo off
    set ReplaceNotepad=%cd%\notepad.exe
    %systemdrive%
    cd %windir%
    FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
    takeown /f %%n
    echo copy %ReplaceNotePad% %%n 
    )
    pause
    set ReplaceNotePad
    

    Here's where I found NOTEPAD in the 32/64 Win7…

    Win7-32
    C:\Windows\System32\notepad.exe
    C:\Windows\winsxs\x86_microsoft-windows-notepadwin_31bf3856ad364e35_6.1.7600.16385_none_42a023025c60a33a\notepad.exe
    C:\Windows\winsxs\x86_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_6ef0e39ed15350e4\notepad.exe
    C:\Windows\notepad.exe

    Win7-64
    C:\Windows\System32\notepad.exe
    C:\Windows\SysWOW64\notepad.exe
    C:\Windows\winsxs\amd64_microsoft-windows-notepadwin_31bf3856ad364e35_6.1.7600.16385_none_9ebebe8614be1470\notepad.exe
    C:\Windows\winsxs\amd64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_cb0f7f2289b0c21a\notepad.exe
    C:\Windows\winsxs\wow64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_d5642974be118415\notepad.exe
    C:\Windows\notepad.exe

    There is no preview so good luck reading this.  (This will probably be my only post to sourceforge)

     
  • Lexxter

    Lexxter - 2010-05-01

    Crap hold on, with that ECHO it wont do anything but take ownership, and without the echo, mine still says access denied.

     
  • Lexxter

    Lexxter - 2010-05-01

    You'll need to remove the ECHO from the ECHO COPY line.
    Like this…

    @echo off
    set ReplaceNotepad=%cd%\notepad.exe
    %systemdrive%
    cd %windir%
    FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
    takeown /f %%n
    copy %ReplaceNotePad% %%n 
    )
    set ReplaceNotePad
    pause
    
     
  • Lexxter

    Lexxter - 2010-05-01

    Use this.
    Note the echo on cacls is intentional.

    @echo off
    set ReplaceNotepad=%cd%\notepad.exe
    %systemdrive%
    cd %windir%
    FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
    takeown /f %%n
    echo Y|cacls %%n /Grant %USERNAME%:F
    copy %ReplaceNotePad% %%n 
    )
    set ReplaceNotePad=
    pause
    

    Now when I run Notepad from Start, it opens Notepad++.
    Post if you have any problems.

     
  • Anonymous - 2010-08-05

    Still had issues with 64bit Windows 7, where though not opened, some of the copies of notepad were locked. To correct, modified script as follows:

    @echo off

    set ReplaceNotepad=%cd%\notepad.exe
    %systemdrive%
    cd %windir%

    FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
    takeown /f %%n
    echo Y|cacls %%n /Grant %USERNAME%:F
    copy %ReplaceNotePad% %%n
    if errorlevel 1 call :whoops %%n
    )

    set ReplaceNotePad=
    pause
    goto :exit

    :whoops
    SETLOCAL ENABLEEXTENSIONS
    SETLOCAL ENABLEDELAYEDEXPANSION
    set OriginalNP=%1
    set NPPath=!OriginalNotePad:~0,-12!

    REM Fix if issue is that NotePad.EXE is in use
    move !OriginalNP! !NPPPath!\notepad.original
    copy %ReplaceNotePad% !OriginalNP!
    if not errorlevel 1 goto :continue

    REM Fix if issue is also directory permissions
    takenown /f !NPPath!
    echo Y|cacls !NPPath! /Grant %USERNAME%:F
    move !OriginalNP! !NPPPath!\notepad.original
    copy %ReplaceNotePad% !OriginalNP!
    goto :continue

    :continue
    echo ***
    echo *** After next reboot, delete the locked file
    echo *** !NPPPath!\notepad.original
    echo ***
    goto :exit

    :exit

     
  • komurczak1476

    komurczak1476 - 2010-08-12

    Annoyed by the bunch of walkarounds and almost-working scripts found here and on the other forums, I tried to write an app which solves the problem.
    You can try it here: http://www.sendspace.com/file/j353k8

    It isn't perfect and I wouldn't be suprise if some strange errors pop up, but it works. The app replaces notepad.exe (using takeown and icacls) and then redirects parameters send to notepad.exe to your notepad (eg. notepad++). Config is stored in system32/notepad.exe.conf.

    Tested on win7 32bit. Hope somebody find it useful.

     
  • Anonymous - 2011-04-27

    Improvement for WINDOWS 7 64 Bit Version:

    @echo off
    echo Note: notepad64.exe (notepad++ Launcher) must be in same directory to work
    echo Working…
    set StartDir=%cd%
    set ReplaceNotepad=%StartDir%\notepad64.exe
    %systemdrive%
    cd %windir%
    FOR /F "tokens=*" %%n IN ('dir /b notepad.exe /s') DO (
    takeown /f %%n
    echo Y|cacls %%n /Grant %USERNAME%:F
    copy %%n %%n.old
    copy "%ReplaceNotePad%" %%n
    if errorlevel 1 call :whoops %%n
    )
    set ReplaceNotePad=
    pause
    goto :exit
    :whoops
    SETLOCAL ENABLEEXTENSIONS
    SETLOCAL ENABLEDELAYEDEXPANSION
    set OriginalNP=%2
    set NPPath=!OriginalNotePad:~0,-12!
    REM Fix if issue is that NotePad.EXE is in use
    move !OriginalNP! !NPPPath!\notepad.original
    copy %ReplaceNotePad% !OriginalNP!
    if not errorlevel 1 goto :continue
    REM Fix if issue is also directory permissions
    takenown /f !NPPath!
    echo Y|cacls !NPPath! /Grant %USERNAME%:F
    move !OriginalNP! !NPPPath!\notepad.original
    copy %ReplaceNotePad% !OriginalNP!
    goto :continue
    :continue
    echo ***
    echo *** After next reboot, delete the locked file
    echo *** !NPPPath!\notepad.original
    echo ***
    goto :exit
    :exit
    cd /d %StartDir%

     
  • McLoo

    McLoo - 2011-05-03

    Why don't use the more elegant way: Hijack notepad.exe
    A short howto can be found at the Notepad2 Homepage. Works perfectly for me. Mind the difference between 64 and 32 bit systems. btw: Sysinternals Process Explorer uses the same mechanism when it gets set as task manager

    http://www.flos-freeware.ch/doc/notepad2-Replacement.html

    McLoo

     
  • Zhang Yin

    Zhang Yin - 2011-12-07

    The elegant way, hijacking notepad.exe, is introduced on http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Replacing_Notepad, in the "Non destructive approach" section. A simple but smart VBscript, for which I'm thankful:

    '// DISCLAIMER
    '// THIS COMES WITH NO WARRANTY, IMPLIED OR OTHERWISE. USE AT YOUR OWN RISK
    '// IF YOU ARE NOT COMFORTABLE EDITING THE REGISTRY THEN DO NOT USE THIS SCRIPT
    '//
    '// NOTES:
    '// This affects all users.
    '// This will prevent ANY executable named notepad.exe from running located anywhere on this computer!!
    '//
    '// Save this text to your notepad++ folder as a text file named npp.vbs (some AV don't like vbs, get a different AV :-P )
    '//
    '// USAGE
    '// 1)
    '// Navigate to registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\
    '//
    ' // 2)
    '// Add new subkey called notepad.exe
    '// This step is what tells windows to use the notepad++ exe, to undo simply delete this key
    '//
    '// 3)
    '// Create new Sting Value called Debugger
    '//
    '// 4)
    '// Modify value and enter wscript.exe "path to npp.vbs" e.g. wscript.exe "C:\Program Files\Notepad++\npp.vbs"

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

    But wait. This script has trouble when the fullname of a file to be opened contains spaces. The command it generates would be something like

    "C:\Notepad++\notepad++.exe" "C:\read" "me.txt"
    

    , while I want to open

    "C:\read me.txt"
    


    My solution here, not possible without the original script:

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