Create settings per-user based on same workstation

From NSIS Wiki
Jump to navigationJump to search
Author: Dafi (talk, contrib)


Description

This script is used by my Copy2Clip utility to create setting per-user based. User with administration rights installs the Copy2Clip application then when other users log on the workstation their settings are created. Pay your attention to RegisterActiveSetup function, the core of per-user settings.

The Script

; Turn off old selected section
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Different manner to express version number
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!define PRODUCT_VERSION                      "1.0.5a"
!define PRODUCT_VERSION_NO_DOTS              "105a"
; This hasn't the letter
!define ACTIVE_SETUP_VERSION_NUMBER          "1,0,5"
 
!define PRODUCT_NAME                         "Copy2Clip"
!define PRODUCT_PUBLISHER                    "DafiTech"
!define PRODUCT_WEB_SITE                     "http://utenti.tripod.it/DafiZone"
!define PRODUCT_UNINST_KEY                   "Software\Microsoft\Windows\CurrentVersion\Uninstall\DafiTech.${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY              "HKLM"
!define PRODUCT_SETUP_NAME                   "..\Release\copy2clip${PRODUCT_VERSION_NO_DOTS}_setup.exe"
 
!define OUT_SHELL_EXT_DIR                    "$SYSDIR\ShellExt\DafiTech\Cpy2Clip"
 
; Registry keys
!define C2C_GUID                            "{28681820-917D-11d5-8177-005056FDDA4B}"
 
; Used by Active Setup
!define ACTIVE_SETUP_REG_KEY                "SOFTWARE\Microsoft\Active Setup\Installed Components"
!define ACTIVE_SETUP_DEFAULT_NAME           "Copy2Clip v${PRODUCT_VERSION}"
!define ACTIVE_SETUP_COMPONENT_ID           "Copy2Clip"
!define ACTIVE_SETUP_STUB_PATH              "rundll32.exe ${OUT_SHELL_EXT_DIR}\cpy2clip.dll,CreateUserSettings"
 
SetCompressor lzma
 
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
 
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "copy2clip.bmp"
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
 
!define MUI_ICON "..\res\clip.ico"
!define MUI_UNICON "..\res\clip.ico"
 
 
; Welcome page
;!insertmacro MUI_PAGE_WELCOME
 
; License page
!insertmacro MUI_PAGE_LICENSE "license.rtf"
 
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
 
; Finish page
;!define MUI_FINISHPAGE_SHOWREADME "${OUT_SHELL_EXT_DIR}\whatsnew.txt"
;!insertmacro MUI_PAGE_FINISH
 
; Uninstaller pages
;!insertmacro MUI_UNPAGE_INSTFILES
 
; Language files
!insertmacro MUI_LANGUAGE "English"
 
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_SETUP_NAME}"
InstallDir "${OUT_SHELL_EXT_DIR}"
ShowInstDetails show
ShowUnInstDetails show
 
Section "SezionePrincipale" SEC01
  SetOutPath "${OUT_SHELL_EXT_DIR}"
  SetOverwrite ifnewer
  File "..\Release\Cpy2Clip.dll"
  File "..\Release\Cpy2Clip.hlp"
 
  File "..\deploy\newpatts.ini"
  File "..\deploy\sample.ini"
  File "..\whatsnew.txt"
SectionEnd
 
Section -Post
  Call RegisterShellExtension
  Call RegisterActiveSetup
 
  WriteUninstaller "${OUT_SHELL_EXT_DIR}\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"           "$(^Name) (remove only)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"       "${OUT_SHELL_EXT_DIR}\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion"        "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout"          "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher"             "${PRODUCT_PUBLISHER}"
SectionEnd
 
 
;Function un.onUninstSuccess
;  HideWindow
;  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) has been removed from your computer"
;FunctionEnd
 
;Function un.onInit
;  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you really want to remove $(^Name) from your computer ?" IDYES +2
;  Abort
;FunctionEnd
 
Section Uninstall
  Call un.RegisterShellExtension
  Call un.RegisterActiveSetup
 
  Delete "${OUT_SHELL_EXT_DIR}\uninst.exe"
  Delete "${OUT_SHELL_EXT_DIR}\whatsnew.txt"
  Delete "${OUT_SHELL_EXT_DIR}\sample.ini"
  Delete "${OUT_SHELL_EXT_DIR}\newpatts.ini"
  Delete "${OUT_SHELL_EXT_DIR}\CPY2CLIP.HLP"
  Delete "${OUT_SHELL_EXT_DIR}\CPY2CLIP.gid"
  Delete "${OUT_SHELL_EXT_DIR}\CPY2CLIP.fts"
  Delete /REBOOTOK "${OUT_SHELL_EXT_DIR}\Cpy2Clip.dll"
 
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  SetAutoClose true
SectionEnd
 
Function RegisterShellExtension
  ; Note double quoted path to support path names with spaces. See Q69752
  ;WriteRegStr HKLM "${PRODUCT_RUN_ONCE_SETUP}" "${RegisterMessage}" "$SYSDIR\REGSVR32.EXE /s /c $\"${OUT_SHELL_EXT_DIR}\cpy2clip.dll$\""
  SetOutPath "${OUT_SHELL_EXT_DIR}"
  RegDll "cpy2clip.dll"
FunctionEnd
 
Function un.RegisterShellExtension
  ; Note double quoted path to support path names with spaces. See Q69752
  ;WriteRegStr HKLM "${PRODUCT_RUN_ONCE_SETUP}" "${UnRegisterMessage}" "$SYSDIR\REGSVR32.EXE /s /u $\"${OUT_SHELL_EXT_DIR}\cpy2clip.dll$\""
  SetOutPath "${OUT_SHELL_EXT_DIR}"
  UnRegDll "cpy2clip.dll"
FunctionEnd
 
Function RegisterActiveSetup
  WriteRegStr HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" ""              "${ACTIVE_SETUP_DEFAULT_NAME}"
  WriteRegStr HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" "StubPath"      "${ACTIVE_SETUP_STUB_PATH}"
  WriteRegStr HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" "ComponentID"   "${ACTIVE_SETUP_COMPONENT_ID}"
  WriteRegBin HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" "IsInstalled"   01000000
  WriteRegStr HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" "Version"       "${ACTIVE_SETUP_VERSION_NUMBER}"
  WriteRegStr HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}" "Locale"        "*"
FunctionEnd
 
Function un.RegisterActiveSetup
  DeleteRegKey  HKLM "${ACTIVE_SETUP_REG_KEY}\${C2C_GUID}"
FunctionEnd