A simple windows default notepad replacement script: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Removed entire paragraph linking to my site as that directory and resource no longer exist, and anyone who cares will build the damn script themselves :D)
(Removed references to aranjedeath and aranjepack)
Line 21: Line 21:
!define VERSION "1.0_Final"
!define VERSION "1.0_Final"
Name "Notepad2 Replacer Version ${VERSION}"
Name "Notepad2 Replacer Version ${VERSION}"
Caption "Aranjedeath's Notepad2 Installer Version ${VERSION}"
OutFile "Notepad2_Installer_${VERSION}.exe"
OutFile "Notepad2_Installer_${VERSION}.exe"
CRCCheck force
CRCCheck force
Line 51: Line 50:
GetTempFileName $R0
GetTempFileName $R0
   FileOpen $0 $R0 "w"
   FileOpen $0 $R0 "w"
   FileWrite $0 "<html><body><h1>Thank you for installing Aranjepack, If you have any questions, please contact me in whatever way you see fit.</h1></body></html>"
   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
   FileClose $0
   ExecWait '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$R0"'
   ExecWait '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$R0"'

Revision as of 17:30, 19 March 2011

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