Scripts of NSIS


; DNW.nsi
;
; This script is based on example1.nsi, but it remember the directory, 
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install DNW.nsi into a directory that the user selects.
;
; See install-shared.nsi for a more robust way of checking for administrator rights.
; See install-per-user.nsi for a file association example.

;--------------------------------

; The name of the installer
Name "DNW"

; The file to write
OutFile "DNWInstaller.exe"

; Request application privileges for Windows Vista and higher
RequestExecutionLevel admin

; Build Unicode installer
Unicode True

; The default installation directory
InstallDir $PROGRAMFILES\DNW

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\DNW" "Install_Dir"

;--------------------------------

; Pages

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

; The stuff to install

Section "DNW (required)"

  SectionIn RO

  ; Set output path to the installation directory.
  SetOutPath $INSTDIR

  ; Put file there
  File "DNW.exe"
  File "makeData.exe"

  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\DNW "Install_Dir" "$INSTDIR"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "DisplayName" "DNW"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "NoRepair" 1
  WriteUninstaller "$INSTDIR\uninstall.exe"

SectionEnd

Section

  SetOutPath "$INSTDIR\data"
  SetOverwrite on
  File /nonfatal /r "$data\*.*"
  AccessControl::GrantOnFile "$INSTDIR\data" "(S-1-1-0)" "FullAccess"
  AccessControl::GrantOnFile "$INSTDIR\data" "(S-1-5-32-545)" "FullAccess"
# Give all authentificated users (BUILTIN\Users) full access on
# the registry key HKEY_LOCAL_MACHINE\Software\DNW
  AccessControl::GrantOnRegKey \
    HKLM "Software\DNW\data" "(BU)" "FullAccess"
  Pop $0

SectionEnd

; Optional section 
Section "Start Menu Shortcuts"

  CreateDirectory "$SMPROGRAMS\DNW"
  CreateShortcut "$SMPROGRAMS\DNW\Uninstall.lnk" "$INSTDIR\uninstall.exe"
  SetOutPath "$INSTDIR"
  CreateShortcut "$SMPROGRAMS\DNW\DNW.lnk" "$INSTDIR\DNW.exe"

SectionEnd

; Optional section
Section "Desktop Shortcut"

  SetOutPath "$INSTDIR"
  CreateShortcut "$DESKTOP\DNW.lnk" "$INSTDIR\DNW.exe"

SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"

  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW"
  DeleteRegKey HKLM "SOFTWARE\DNW"

  ; Remove files and uninstaller
  Delete "$INSTDIR\*.*"
  Delete "$INSTDIR\data\*.*"

  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\DNW\*.lnk"
  Delete "$DESKTOP\DNW.lnk"

  ; Remove directories
  RMDir "$INSTDIR\DNW\data"
  RMDir "$INSTDIR\DNW"
  RMDir "$INSTDIR"
  RMDir /r "$INSTDIR"

SectionEnd

留言