3 Interactive User (MediumIL) Admin user (HighIL)
4 ***[Setup.exe]************* ***[Setup.exe]**************
6 * +++[.OnInit]+++++++++++ * * +++[.OnInit]++++++++++++ *
7 * + UAC_RunElevated >---+-+----> * + + *
8 * + NSIS.Quit + * * + + *
9 * +++++++++++++++++++++++ * * ++++++++++++++++++++++++ *
12 * +++[Section]+++++++++++ * * +++[Section]++++++++++++ *
13 * + + * /--+-+-<UAC_AsUser_ExecShell+ *
14 * +++++++++++++++++++++++ * | * ++++++++++++++++++++++++ *
16 * Win32.ShellExecute <---+--/ * *
18 *************************** ****************************
28 !verbose ${UAC_VERBOSE}
30 !define UAC_HDR__INC 0x00020400 ;MMmmbbrr
38 ** Starts the elevation operation.
42 ** $0: Win32 error code (0 on success, 1223 if user aborted elevation dialog, anything else should be treated as a fatal error)
44 ** 0 UAC is not supported by the OS
45 ** 1 Started a elevated child process, the current process should act like a wrapper (Call Quit without any further processing)
46 ** 2 The process is already running @ HighIL (Member of admin group)
47 ** 3 You should call RunElevated again (This can happen if a user without admin priv. is used in the runas dialog)
48 ** $2: If $0==0 && $1==1: ExitCode of the elevated fork process (The NSIS errlvl is also set)
49 ** $3: If $0==0: 1 if the user is a member of the admin group or 0 otherwise
51 !macro UAC_RunElevated
54 !macro UAC_PageElevation_RunElevated
57 /*!macro UAC_OnInitElevation_RunElevated
60 !macro UAC_OnInitElevation_OnGuiInit
65 /* UAC_GetIntegrityLevel <NSISVar:Output | "s">
67 ** Get integrity level of current process
70 !macro UAC_GetIntegrityLevel outvar
72 !if "${outvar}" != "s"
81 ** Is the current process running with administrator privileges? Result in $0
83 ** ${If} ${UAC_IsAdmin} ...
89 !define UAC_IsAdmin `"" UAC_IsAdmin ""`
90 !macro _UAC_IsAdmin _a _b _t _f
91 !insertmacro _UAC_MakeLL_Cmp _!= 0 2s
96 /* UAC_IsInnerInstance
98 ** Does the current process have a NSIS/UAC parent process that is part of the elevation operation?
100 ** ${If} ${UAC_IsInnerInstance} ...
103 !macro UAC_IsInnerInstance
106 !define UAC_IsInnerInstance `"" UAC_IsInnerInstance ""`
107 !macro _UAC_IsInnerInstance _a _b _t _f
108 !insertmacro _UAC_MakeLL_Cmp _!= 0 3s
113 /* UAC_PageElevation_OnInit, UAC_PageElevation_OnGuiInit,
115 ** Helper macros for elevation on a custom elevation page, see the DualMode example for more information.
118 !macro UAC_Notify_OnGuiInit
121 !macro UAC_PageElevation_OnGuiInit
122 !insertmacro UAC_Notify_OnGuiInit
124 !macro UAC_PageElevation_OnInit
126 ${IfThen} ${Errors} ${|} Quit ${|}
131 /* UAC_AsUser_Call <Function|Label> <NSISAddressName> <UAC_* flags>
133 ** Calls a function or label in the user process instance.
134 ** All the UAC_AsUser_* macros use this helper macro.
137 !define UAC_SYNCREGISTERS 0x1
138 ;define UAC_SYNCSTACK 0x2
139 !define UAC_SYNCOUTDIR 0x4
140 !define UAC_SYNCINSTDIR 0x8
141 ;define UAC_CLEARERRFLAG 0x10
142 !macro UAC_AsUser_Call type name flags
144 Get${type}Address $0 ${name}
146 !verbose ${UAC_VERBOSE}
147 !insertmacro _UAC_ParseDefineFlagsToInt _UAC_AsUser_Call__flags ${flags}
149 StrCpy $0 "1$0:${_UAC_AsUser_Call__flags}"
150 !undef _UAC_AsUser_Call__flags
158 ** UAC_AsUser_GetSection <Flags|InstTypes|Size|Text> <SectionIndex> <NSISVar:Output>
160 !macro UAC_AsUser_GetSection secprop secidx outvar
161 !insertmacro _UAC_AsUser_GenOp ${outvar} SectionGet${secprop} ${secidx} ""
167 ** UAC_AsUser_GetGlobalVar <NSISVar:SourceAndOutput>
168 ** UAC_AsUser_GetGlobal <NSISVar:Output> <NSISVar:Source>
170 !macro UAC_AsUser_GetGlobalVar var
171 !insertmacro _UAC_AsUser_GenOp ${var} StrCpy "" ${var}
173 !macro UAC_AsUser_GetGlobal outvar srcvar
174 !insertmacro _UAC_AsUser_GenOp ${outvar} StrCpy "" ${srcvar}
180 ** UAC_AsUser_ExecShell <Verb> <ApplicationOrFile> <Parameters> <Working Directory> <SW_*>
182 ** Call ExecShell in the user process instance.
185 !macro UAC_AsUser_ExecShell verb command params workdir show
186 !insertmacro _UAC_IncL
187 goto _UAC_L_E_${__UAC_L}
189 ExecShell "${verb}" "${command}" '${params}' ${show}
192 !if "${workdir}" != ""
194 SetOutPath "${workdir}"
196 !insertmacro UAC_AsUser_Call Label _UAC_L_F_${__UAC_L} ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} #|${UAC_CLEARERRFLAG}
197 !if "${workdir}" != ""
205 !macro _UAC_MakeLL_Cmp cmpop cmp pluginparams
206 !insertmacro _LOGICLIB_TEMP
207 UAC::_ ${pluginparams}
209 !insertmacro ${cmpop} $_LOGICLIB_TEMP ${cmp} `${_t}` `${_f}`
211 !macro _UAC_definemath def val1 op val2
212 !define /math _UAC_definemath "${val1}" ${op} ${val2}
216 !define ${def} "${_UAC_definemath}"
217 !undef _UAC_definemath
219 !macro _UAC_ParseDefineFlags_orin parse outflags
220 !searchparse /noerrors ${${parse}} "" _UAC_ParseDefineFlags_orin_f1 "|" _UAC_ParseDefineFlags_orin_f2
221 !define _UAC_ParseDefineFlags_orin_this ${_UAC_ParseDefineFlags_orin_f1}
223 !define ${parse} ${_UAC_ParseDefineFlags_orin_f2}
224 !define _UAC_ParseDefineFlags_orin_saveout ${${outflags}}
226 !define /math ${outflags} "${_UAC_ParseDefineFlags_orin_saveout}" | "${_UAC_ParseDefineFlags_orin_this}"
227 !undef _UAC_ParseDefineFlags_orin_saveout
228 !undef _UAC_ParseDefineFlags_orin_this
229 !ifdef _UAC_ParseDefineFlags_orin_f1
230 !undef _UAC_ParseDefineFlags_orin_f1
232 !ifdef _UAC_ParseDefineFlags_orin_f2
233 !undef _UAC_ParseDefineFlags_orin_f2
236 !macro _UAC_ParseDefineFlags_Begin _outdef _in
237 !define _UAC_PDF${_outdef}_parse "${_in}"
238 !define _UAC_PDF${_outdef}_flags ""
239 !define _UAC_PDF${_outdef}_r 0
240 !insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags ;0x1
241 !insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags ;0x2
242 !insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags ;0x4
243 !insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags ;0x8
244 !insertmacro _UAC_ParseDefineFlags_orin _UAC_PDF${_outdef}_parse _UAC_PDF${_outdef}_flags ;0x10
246 !macro _UAC_ParseDefineFlags_End _outdef
247 !define ${_outdef} ${_UAC_PDF${_outdef}_r}
248 !undef _UAC_PDF${_outdef}_r
249 !undef _UAC_PDF${_outdef}_flags
250 !undef _UAC_PDF${_outdef}_parse
252 !macro _UAC_ParseDefineFlags_IncludeFlag _outdef flag
253 !if ${_UAC_PDF${_outdef}_flags} & ${flag}
254 !insertmacro _UAC_definemath _UAC_PDF${_outdef}_r ${_UAC_PDF${_outdef}_r} | ${flag}
257 !macro _UAC_ParseDefineFlagsToInt _outdef _in
258 !insertmacro _UAC_ParseDefineFlags_Begin _UAC_ParseDefineFlagsToInt_tmp "${_in}"
259 !define ${_outdef} ${_UAC_PDF_UAC_ParseDefineFlagsToInt_tmp_flags}
260 !insertmacro _UAC_ParseDefineFlags_End _UAC_ParseDefineFlagsToInt_tmp
261 !undef _UAC_ParseDefineFlagsToInt_tmp
264 !insertmacro _UAC_definemath __UAC_L "${__UAC_L}" + 1
266 !macro _UAC_AsUser_GenOp outvar op opparam1 opparam2
267 !define _UAC_AUGOGR_ID _UAC_AUGOGR_OP${outvar}${op}${opparam1}${opparam2}
268 !ifndef ${_UAC_AUGOGR_ID} ;Has this exact action been done before?
270 !define ${_UAC_AUGOGR_ID} $1
272 !define ${_UAC_AUGOGR_ID} $0
274 !if "${opparam1}" == ""
275 !define _UAC_AUGOGR_OPP1 ${${_UAC_AUGOGR_ID}}
276 !define _UAC_AUGOGR_OPP2 ${opparam2}
278 !define _UAC_AUGOGR_OPP1 ${opparam1}
279 !define _UAC_AUGOGR_OPP2 ${${_UAC_AUGOGR_ID}}
281 goto ${_UAC_AUGOGR_ID}_C
283 ${op} ${_UAC_AUGOGR_OPP1} ${_UAC_AUGOGR_OPP2}
286 !undef _UAC_AUGOGR_OPP1
287 !undef _UAC_AUGOGR_OPP2
289 push ${${_UAC_AUGOGR_ID}}
290 !insertmacro UAC_AsUser_Call Label ${_UAC_AUGOGR_ID}_F ${UAC_SYNCREGISTERS}
291 StrCpy ${outvar} ${${_UAC_AUGOGR_ID}}
292 pop ${${_UAC_AUGOGR_ID}}
293 !undef _UAC_AUGOGR_ID
299 !endif /* UAC_HDR__INC */