LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default NSIS VBA Add-In Installer

I recently tackled the job of writing an installer/uninstaller for a
VBA Add-in to distribute to my coworkers. I looked into using a VBA
installer, but was concerned that the default macro security settings
in Office 2003 might prevent the installer from executing. I wrote the
NSIS script below to directly register the Add-In as installed in the
Add-In Manager list. I'm new to using NSIS so it's not the most elegant
script but it does the job. I hope someone might find it useful.

Dave

; NSIS Excel Add-In Installer Script
; Include
!include MUI.nsh
!include LogicLib.nsh

; General
Name "NSIS Test"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\NSIS Test"
InstallDirRegKey HKCU "Software\NSIS Test" "InstallDir" ;
Overrides InstallDir

; Interface Settings
!define MUI_ABORTWARNING

; Installer Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

; Uninstaller Pages
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

; Languages
!insertmacro MUI_LANGUAGE "English"

; Installer Section
Section "-Install"
SetOutPath "$INSTDIR"

; ADD FILES HERE
File "NSISTest.xla"
File "readme.txt"

; Check Installed Excel Version
ReadRegStr $1 HKCR "Excel.Application\CurVer" ""

${If} $1 == 'Excel.Application.8' ; Excel 95
StrCpy $2 "8.0"
${ElseIf} $1 == 'Excel.Application.9' ; Excel 2000
StrCpy $2 "9.0"
${ElseIf} $1 == 'Excel.Application.10' ; Excel XP
StrCpy $2 "10.0"
${ElseIf} $1 == 'Excel.Application.11' ; Excel 2003
StrCpy $2 "11.0"
${Else}
Abort "An appropriate version of Excel is not installed.
$\nNSIS Test setup will be canceled."
${EndIf}

; Find available "OPEN" key
StrCpy $3 ""
loop:
ReadRegStr $4 HKCU
"Software\Microsoft\Office\$2\Excel\Options" "OPEN$3"
${If} $4 == ""
; Available OPEN key found
${Else}
IntOp $3 $3 + 1
Goto loop
${EndIf}

; Write install data to registry
WriteRegStr HKCU "Software\NSIS Test" "InstallDir" $INSTDIR
; Install Directory
WriteRegStr HKCU "Software\NSIS Test" "ExcelCurVer" $2
; Current Excel Version

; Write key to install AddIn in Excel Addin Manager
WriteRegStr HKCU "Software\Microsoft\Office\$2\Excel\Options"
"OPEN$3" '"$INSTDIR\NSISTest.xla"'

; Write keys to uninstall
WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninsta ll\NSIS Test"
"DisplayName" "NSIS Test"
WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninsta ll\NSIS Test"
"UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninsta ll\NSIS Test"
"NoModify" 1
WriteRegDWORD HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninsta ll\NSIS Test"
"NoRepair" 1

; Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd

; Uninstaller Section
Section "Uninstall"
; ADD FILES HERE...
Delete "$INSTDIR\NSISTest.xla"
;Delete "$INSTDIR\EngFunctHelp.chm"
Delete "$INSTDIR\readme.txt"
Delete "$INSTDIR\uninstall.exe"

RMDir "$INSTDIR"

; Find AddIn Manager Key and Delete
; AddIn Manager key name and location may have changed since
installation depending on actions taken by user in AddIn Manager.
; Need to search for the target AddIn key and delete if found.
ReadRegStr $2 HKCU "Software\NSIS Test" "ExcelCurVer"
StrCpy $3 ""

loop:
ReadRegStr $4 HKCU
"Software\Microsoft\Office\$2\Excel\Options" "OPEN$3"
${If} $4 == '"$INSTDIR\NSISTest.xla"'
; Found Key
DeleteRegValue HKCU
"Software\Microsoft\Office\$2\Excel\Options" "OPEN$3"
${ElseIf} $4 == ""
; Blank Key Found. Addin is no longer installed in
AddIn Manager.
; Need to delete Addin Manager Reference.
DeleteRegValue HKCU
"Software\Microsoft\Office\$2\Excel\Add-in Manager"
"$INSTDIR\NSISTest.xla"
${Else}
IntOp $3 $3 + 1
Goto loop
${EndIf}

DeleteRegKey HKCU "Software\NSIS Test"
DeleteRegKey HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninsta ll\NSIS Test"
SectionEnd

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
windows installer linda m Excel Discussion (Misc queries) 1 May 18th 07 03:10 PM
windows installer pop up joel Excel Discussion (Misc queries) 0 July 31st 06 04:43 PM
Excel Installer Chris Watson Excel Discussion (Misc queries) 1 February 8th 06 02:57 AM
installer wdmurry Excel Discussion (Misc queries) 0 April 20th 05 04:31 AM
library installer Laurent M Excel Discussion (Misc queries) 1 January 31st 05 11:47 PM


All times are GMT +1. The time now is 10:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"