forked from pulibrary/ExcelAlmaLookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatalogLookup.nsi
120 lines (96 loc) · 3.5 KB
/
CatalogLookup.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
; NSIS Excel Add-In Installer Script
RequestExecutionLevel user
!include MUI.nsh
!include LogicLib.nsh
; General
!define filename "CatalogLookup.xlam"
!define displayname "Excel Local Catalog Lookup"
Name "${displayname}"
OutFile "CatalogLookupInstaller.exe"
InstallDir "$APPDATA\${displayname}"
InstallDirRegKey HKCU "Software\${displayname}" "InstallDir" ;
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
; Interface Settings
!define MUI_ABORTWARNING
;Prerequisites section
Section "-Prerequisites"
SectionEnd
SetOverwrite On
; Installer Section
Section "-Install"
SetOutPath $INSTDIR
; ADD FILES HERE
File "${filename}"
; Check Installed Excel Version
ReadRegStr $1 HKCR "Excel.Application\CurVer" ""
${If} $1 == 'Excel.Application.12' ; Excel 2007
StrCpy $2 "12.0"
${ElseIf} $1 == 'Excel.Application.14' ; Excel 2010
StrCpy $2 "14.0"
${ElseIf} $1 == 'Excel.Application.15' ; Excel 2013
StrCpy $2 "15.0"
${ElseIf} $1 == 'Excel.Application.16' ; Excel 2016
StrCpy $2 "16.0"
${Else}
Abort "An appropriate version of Excel is not installed. $\n${displayname} 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\${displayname}" "InstallDir" $INSTDIR
; Install Directory
WriteRegStr HKCU "Software\${displayname}" "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\${filename}"'
; Write keys to uninstall
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${displayname}" "DisplayName" "${displayname}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${displayname}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${displayname}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${displayname}" "NoRepair" 1
; Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
; Uninstaller Section
Section "Uninstall"
StrCpy $INSTDIR "$APPDATA\${displayname}"
; ADD FILES HERE...
Delete "$INSTDIR\${filename}"
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\${displayname}" "ExcelCurVer"
StrCpy $3 ""
loop:
ReadRegStr $4 HKCU "Software\Microsoft\Office\$2\Excel\Options" "OPEN$3"
${If} $4 == '"$INSTDIR\${filename}"'
; 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\${filename}"
${Else}
IntOp $3 $3 + 1
Goto loop
${EndIf}
DeleteRegKey HKCU "Software\${displayname}"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${displayname}"
SectionEnd