This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnsi.nsi
92 lines (72 loc) · 2.41 KB
/
nsi.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
!define NAME "Mouseable"
!define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
Name "${NAME}"
OutFile "build\installer.exe"
Unicode True
RequestExecutionLevel Admin ; Request admin rights on WinVista+ (when UAC is turned on)
InstallDir "$ProgramFiles\$(^Name)"
InstallDirRegKey HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString"
!include LogicLib.nsh
!include Integration.nsh
Page Directory
Page InstFiles
Uninstpage UninstConfirm
Uninstpage InstFiles
!macro EnsureAdminRights
UserInfo::GetAccountType
Pop $0
${If} $0 != "admin" ; Require admin rights on WinNT4+
MessageBox MB_IconStop "Administrator rights required!"
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
!macroend
Function .onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Function un.onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Section "Kill process"
StrCpy $1 "mouseable.exe"
nsProcess::_FindProcess "$1"
Pop $R0
${If} $R0 = 0
nsProcess::_KillProcess "$1"
Pop $R0
MessageBox MB_OK 'process has been killed.'
Sleep 500
${EndIf}
SectionEnd
Section "Program files (Required)"
SectionIn Ro
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}"
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\mouseable.exe,0"
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"'
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "QuietUninstallString" '"$InstDir\Uninst.exe" /S'
WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoModify" 1
WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1
File "/oname=$InstDir\mouseable.exe" "build\portable.exe" ; Pretend that we have a real application to install
SectionEnd
Section "Start Menu shortcut"
CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\mouseable.exe"
SectionEnd
!macro DeleteFileOrAskAbort path
ClearErrors
Delete "${path}"
IfErrors 0 +3
MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP 'Unable to delete "${path}"!' IDRETRY -3 IDIGNORE +2
Abort "Aborted"
!macroend
Section -Uninstall
!insertmacro DeleteFileOrAskAbort "$InstDir\mouseable.exe"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}"
${UnpinShortcut} "$SMPrograms\${NAME}.lnk"
Delete "$SMPrograms\${NAME}.lnk"
SectionEnd