[sword-devel] BibleCS Installer: HKCU vs HKLM

L.Allan-pbio paraclete at bibleinverse.org
Fri Feb 10 00:25:05 MST 2006


Regarding use of HKCU vs HKLM (split from general Installer thread to be 
focused on this issue alone) :

Here is some sample code for a custom page allowing choice of "Just this 
user" and "All Users". It is pretty stripped down just to illustrate the 
basics of how it works.

(I haven't tested with a "limited user" account to see what happens. I 
suppose that could be detected with Contrib\UserInfo\UserInfo.nsi  and only 
allow "current" and don't even show the custom page ...  my impression is 
that a "limited user" can still read HKLM)

;*************** ini file ************
# HkcuVsHklm_CustomPage.ini

[Settings]
NumFields=2

[Field 1]
Type=RadioButton
Text=Install for just this user
Flags=NOTIFY|GROUP
State=1
Left=0
Right=-10
Top=0
Bottom=12

[Field 2]
Type=RadioButton
Text=Install for all users on this computer
Flags=NOTIFY|NOTABSTOP
State=0
Left=0
Right=-10
Top=20
Bottom=32

********** Installer ***************
!include Sections.nsh
!include "MUI.nsh"

Var HkeyChoice

Page custom PreShowInstallChoices LeaveInstallChoices ": Just this user or 
all users"

!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE English

;--------------------------------
; Installer attributes
Name "Modern UI Test"
OutFile HkcuVsHklm.exe
InstallDir "$PROGRAMFILES\Modern UI Test"
InstallDirRegKey HKCU "Software\Modern UI Test" ""

LangString TEXT_IO_TITLE ${LANG_ENGLISH} "CrossWire family of applications."
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "Explanation about choosing 
'Just this User' vs 'All Users' goes here."

Function .onInit
  DeleteRegValue HKLM "SOFTWARE\CrossWire\The SWORD Project" "HkcuVsHklm"
  DeleteRegValue HKCU "SOFTWARE\CrossWire\The SWORD Project" "HkcuVsHklm"
  StrCpy $HkeyChoice "current"
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "HkcuVsHklm_CustomPage.ini"
FunctionEnd

# Installer sections
Section -Main WriteFiles
SectionEnd

Section -post WriteRegistryEntries
  WriteRegStr SHCTX "SOFTWARE\CrossWire\The SWORD Project" "HkcuVsHklm" 
"$HkeyChoice"
SectionEnd

Function PreShowInstallChoices
  !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "HkcuVsHklm_CustomPage.ini"
FunctionEnd

Function LeaveInstallChoices
  ; At this point the user has either pressed the Next Button or one of our 
custom RadioButtons
  ; We find out which by reading the "Settings" field from the INI file
  !insertmacro MUI_INSTALLOPTIONS_READ $0 "HkcuVsHklm_CustomPage.ini" 
"Settings" "State"
  StrCmp $0 0  NextButtonPicked
  StrCmp $0 1  JustThisUser
  StrCmp $0 2  AllUsers
  Abort ; Return to the page to allow further choices

JustThisUser:
  StrCpy $HkeyChoice "current"
  Abort ; Return to the page

AllUsers:
  StrCpy $HkeyChoice "all"
  Abort ; Return to the page

NextButtonPicked:
  StrCmp $HkeyChoice "current" 0 UseAll
    SetShellVarContext current
    GoTo ChoiceDone

    UseAll:
    SetShellVarContext all

  ChoiceDone:
FunctionEnd

Function .onInstSuccess
  ReadRegStr $0 SHCTX "SOFTWARE\CrossWire\The SWORD Project" "HkcuVsHklm"
  MessageBox MB_OK "Hkey Choice: $0"
FunctionEnd



More information about the sword-devel mailing list