Jump to content

replace notepad in XP with ease


hotkicks
 Share

Recommended Posts

Most people use alternatives to MS notepad. Due to system files protection in windows 2000 and XP, it is often difficult to permanently replace notepad with your preferred text editor in these OS. This script automates the task. It backs up your existing notepad and copies the new notepad to the appropriate folders (depending on your OS type).

How to use

Rename your favourite editor to notepad.exe and put it in the same directory as the script. Run the script.

My favourite editor is the unbeatable metapad http://liquidninja.com/metapad/.

;Notepad Replacement by Kunle Adegoke
;1:23 AM June 24, 2005
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoItSetOption("RunErrorsFatal", 0)
AutoItSetOption("TrayIconHide", 1)

; make sure notepad is not running
If ProcessExists("notepad.exe") Then
MsgBox(64+262144,"Replace Notepad",'Please close all instances of NOTEPAD' & @CRLF & 'and run ' & '"' & @ScriptName & '"' & ' again.')
Exit
EndIf

; check if replacement notepad is in place and get the user's consent

If FileExists(@ScriptDir & "\notepad.exe") Then

$question=MsgBox(64+262144+4,"Replace Notepad (Script by Kunle Adegoke)","Your existing notepad.exe will be replaced" & @CRLF & "with the new notepad.exe contained in" & @CRLF & @CRLF & @ScriptDir & @CRLF & @CRLF & "Do you want to continue?")

If $question=7 Then Exit

Else
MsgBox(64+262144,"Replace Notepad",'notepad.exe not found in' & @CRLF & @CRLF & @ScriptDir & @CRLF & @CRLF & 'Place the replacement "notepad.exe" in this folder' & @CRLF & 'and run ' & '"' & @ScriptName & '"' & ' again.')
Exit
EndIf

;backup the original copy of notepad

$backup=Filecopy(@WindowsDir & "\notepad.exe",@WindowsDir & "\notepad.bak.exe",1)

$gamma=@ScriptDir & "\"& "notepad.exe"
$gamma=FileGetShortName($gamma)
$lambda=@WindowsDir & "\ServicePackFiles\i386"
$lambda=FileGetShortName($lambda)




If @OSType="WIN32_WINDOWS" Then


Run(@ComSpec & " /c copy /y " & $gamma & " " & @WindowsDir,"",@SW_HIDE)

Else

RunWait(@ComSpec & " /c del /s/f/q " & @WindowsDir & "\notepad.exe","",@SW_HIDE)

Sleep(500)

If StringInStr(FileGetAttrib($lambda),"D") Then
Run(@ComSpec & " /c copy /y " & $gamma & " " & $lambda,"",@SW_HIDE)
EndIf

Run(@ComSpec & " /c copy /y " & $gamma & " " & @SystemDir & "\dllcache","",@SW_HIDE)
Run(@ComSpec & " /c copy /y " & $gamma & " " & @WindowsDir,"",@SW_HIDE)
Run(@ComSpec & " /c copy /y " & $gamma & " " & @SystemDir,"",@SW_HIDE)



EndIf

; check success of the copy operation.
; it is sufficient to check only the copy in the Windows directory

$fest=FileGetSize(@ScriptDir & "\notepad.exe")
Sleep(500)
$secund=FileGetSize(@WindowsDir & "\notepad.exe")


If $fest=$secund Then
MsgBox(64+262144,"Notepad Replacement","Done!")
EndIf

Exit

replace.zip

Edited by hotkicks
Link to comment
Share on other sites

Small suggestion?

; make sure notepad is not running
If ProcessExists("notepad.exe") Then
MsgBox(64+262144,"Replace Notepad",'Please close all instances of NOTEPAD' & @CRLF & 'and run ' & '"' & @ScriptName & '"' & ' again.')
Exit
EndIf

How about allowing the user to continue after they close their Notepads?

; Ensure that Notepad is not running
while (processExists("notepad.exe"))
    if (msgBox(0x40031, "Replace Notepad", _
        "Please close all instances of Notepad before continuing.") = 2) then exit
wEnd
Link to comment
Share on other sites

Yes Alex, nice suggestion! It occured to me, but I didn't consider that somebody who seriously wants to replace a particular file will attempt doing so when that file is in use. I added the check only as a precaution, just in case....

Small suggestion?

; make sure notepad is not running
If ProcessExists("notepad.exe") Then
MsgBox(64+262144,"Replace Notepad",'Please close all instances of NOTEPAD' & @CRLF & 'and run ' & '"' & @ScriptName & '"' & ' again.')
Exit
EndIf

How about allowing the user to continue after they close their Notepads?

; Ensure that Notepad is not running
while (processExists("notepad.exe"))
    if (msgBox(0x40031, "Replace Notepad", _
        "Please close all instances of Notepad before continuing.") = 2) then exit
wEnd

<{POST_SNAPBACK}>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...