A simple windows default notepad replacement script: Difference between revisions
m (Reverted edits by RuthMartin to last version by 75.128.2.12) |
m (Reverted edits by 199.48.147.37 to last version by Kichik) |
(One intermediate revision by one other user not shown) | |
(No difference)
|
Latest revision as of 17:22, 15 August 2012
Author: Aranjedeath (talk, contrib) |
Usage
This script does the age-old replacement of the windows default notepad, with something else, in my particular case, I used notepad2. This example assumes only 2 things.
- That you are using windows xp though it should work on other versions
- That your notepad replacement is already named notepad.exe
The Code
Here, I've cut down the script to what you actually need plus a little bit.
!include "MUI2.nsh"
I recommend MUI2, but I don't believe that it will work on nsis compilers before version 2.34 or something. If it doesn't, you may have to use
!include "MUI.nsh"
for the user interface. However, in the interest of size, you could also omit it completely, as except for the uninstaller, the user never sees the window for long enough to care.
!define VERSION "1.0_Final" Name "Notepad2 Replacer Version ${VERSION}" OutFile "Notepad2_Installer_${VERSION}.exe" CRCCheck force AutoCloseWindow true RequestExecutionLevel admin InstallDir $WINDIR\system32 !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES Section "" install SectionIn RO CreateDirectory $PROGRAMFILES\notepadbackup CopyFiles $INSTDIR\dllcache\notepad.exe $PROGRAMFILES\notepadbackup SetOutPath $INSTDIR\dllcache Delete $INSTDIR\dllcache\notepad.exe File "notepad.exe" File "notepad.ini" SetOutPath $INSTDIR Delete $INSTDIR\notepad.exe File "notepad.exe" File "notepad.ini"
As Notepad2 requires an .ini file to keep its settings, I figured it would be cleaner if the installer was the one that placed the file, and removed it, so that it would be more uniform.
WriteUninstaller $INSTDIR\uninstallnotepad2.exe
This next section spawns an Internet Explorer window with a tiny bit of instructions in it, for useability's sake.
GetTempFileName $R0 FileOpen $0 $R0 "w" FileWrite $0 "<html><body><h1>Thank you for installing Software, If you have any questions, please contact me in whatever way you see fit.</h1></body></html>" FileClose $0 ExecWait '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$R0"' Delete /REBOOTOK $R0 SectionEnd UninstallText "This will Rollback the Notepad2 install. Please click uninstall to continue." Section "Uninstall" Delete $INSTDIR\notepad.exe CopyFiles $PROGRAMFILES\notepadbackup\notepad.exe $INSTDIR Delete $INSTDIR\dllcache\notepad.exe CopyFiles $PROGRAMFILES\notepadbackup\notepad.exe $INSTDIR\dllcache Delete $PROGRAMFILES\notepadbackup\notepad.exe Delete /REBOOTOK $INSTDIR\notepad.ini Delete /REBOOTOK $INSTDIR\dllcache\notepad.ini Delete $INSTDIR\uninstallnotepad2.exe RMDir /REBOOTOK "$PROGRAMFILES\notepadbackup" SectionEnd