-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller.nsh
61 lines (49 loc) · 1.99 KB
/
installer.nsh
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
!include "MUI2.nsh"
!include "LogicLib.nsh"
Function customInit
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\20f726f4-eb4b-53a7-a447-f2062c4bad89" "UninstallString"
StrCmp $R0 "" checkAllUsers
MessageBox MB_YESNO|MB_ICONQUESTION "A previous version of ${PRODUCT_NAME} is detected in your User Account. Would you like to uninstall it first?" IDNO done
ClearErrors
ExecWait '$R0 _?=$INSTDIR'
IfErrors done
checkAllUsers:
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\20f726f4-eb4b-53a7-a447-f2062c4bad89" "UninstallString"
StrCmp $R0 "" done
MessageBox MB_YESNO|MB_ICONQUESTION "A previous version of ${PRODUCT_NAME} is detected on your Device. Would you like to uninstall it first?" IDNO done
ClearErrors
ExecWait '$R0 _?=$INSTDIR'
IfErrors done
done:
FunctionEnd
Function un.closePhraseVault
; Check if PhraseVault is running
nsExec::ExecToStack 'tasklist /FI "IMAGENAME eq PhraseVault.exe" /FO CSV /NH'
Pop $0
StrCmp $0 "INFO: No tasks are running which match the specified criteria." notRunning
; If running, ask the user if they want to close it
MessageBox MB_YESNO|MB_ICONQUESTION "PhraseVault is currently running. Would you like to close it before uninstalling?" IDNO notRunning
ClearErrors
nsExec::Exec '"taskkill /IM PhraseVault.exe /F"'
IfErrors notRunning
notRunning:
FunctionEnd
Section "MainSection" SEC01
Call customInit
SetOutPath "$INSTDIR"
ClearErrors
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${PRODUCT_NAME}" "$INSTDIR\PhraseVault.exe"
IfErrors showError skipError
showError:
MessageBox MB_ICONEXCLAMATION "Failed to set autostart registry key."
skipError:
SectionEnd
Section "Install"
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
Section "Un.MainSection" SEC01-Un
Call un.closePhraseVault
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${PRODUCT_NAME}"
Delete "$INSTDIR\*.*"
RMDir "$INSTDIR"
SectionEnd