2 =======================
3 UAC helper include file
4 .......................
6 Macros starting with UAC.I should only be called from the installer and vice versa for UAC.U macros.
13 !define UAC.RunElevatedAndProcessMessages 'UAC::RunElevated '
14 !define UAC.Unload 'UAC::Unload '
15 !define UAC.StackPush 'UAC::StackPush '
17 /*!macro _UAC.BuildOnInitElevationFunc _funcprefix
18 Function ${_funcprefix}onInit
23 !macro _UAC.GenerateSimpleFunction _funcprefix _funcName _funcCode
24 Function ${_funcprefix}${_funcName}
26 #messagebox mb_ok "${_funcprefix}${_funcName}"
30 !macro _UAC.TryDef _d _v
36 !macro _UAC.InitStrings _modeprefix
37 !insertmacro _UAC.TryDef UACSTR.UnDataFile "UAC.dat"
38 !insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvWinErr "Unable to elevate , error $0"
40 !insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvAbortReqAdmin "This installer requires admin access, aborting!"
41 !insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvMustTryAgain "This installer requires admin access, try again"
43 !insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvAbortReqAdmin "This uninstaller requires admin access, aborting!"
44 !insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvMustTryAgain "This uninstaller requires admin access, try again"
48 !ifmacroNdef _UAC.GenerateUninstallerTango
49 !macro _UAC.GenerateUninstallerTango UninstallerFileName
51 !error "UAC: Needs to be called inside a function"
54 !error "UAC: _UAC.GenerateUninstallerTango should only be called by uninstaller, see http://forums.winamp.com/showthread.php?threadid=280330"
56 !ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
59 !insertmacro _UAC.InitStrings 'U.'
60 ReadIniStr $0 "$ExeDir\${UACSTR.UnDataFile}" UAC "Un.Ready"
62 !ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
63 ${AndIf} ${AtLeastWinVista}
66 WriteIniStr "$PluginsDir\${UACSTR.UnDataFile}" UAC "Un.Ready" 1
67 CopyFiles /SILENT "$EXEPATH" "$PluginsDir\${UninstallerFileName}"
69 ${IfThen} ${Silent} ${|} StrCpy $0 "/S " ${|}
70 ExecWait '"$PluginsDir\${UninstallerFileName}" $0/NCRC _?=$INSTDIR' $0
77 !ifmacroNdef _UAC.GenerateOnInitElevationCode
78 !macro _UAC.GenerateOnInitElevationCode _modeprefix
80 !error "UAC: Needs to be called inside a function"
82 !insertmacro _UAC.InitStrings ${_modeprefix}
83 !define _UAC.GOIECUniq L${__LINE__}
84 UAC_Elevate_${_UAC.GOIECUniq}:
86 StrCmp 1223 $0 UAC_ElevationAborted_${_UAC.GOIECUniq} ; UAC dialog aborted by user?
87 StrCmp 0 $0 0 UAC_Err_${_UAC.GOIECUniq} ; Error?
88 StrCmp 1 $1 0 UAC_Success_${_UAC.GOIECUniq} ;Are we the real deal or just the wrapper?
90 UAC_Err_${_UAC.GOIECUniq}:
91 MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvWinErr}"
93 UAC_ElevationAborted_${_UAC.GOIECUniq}:
94 MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvAbortReqAdmin}"
96 UAC_Success_${_UAC.GOIECUniq}:
97 # if $0==0 && $3==1, we are a member of the admin group (Any OS)
98 # if $0==0 && $1==0, UAC not supported (Probably <NT6), run as normal?
99 # if $0==0 && $1==3, we can try to elevate again
100 StrCmp 1 $3 /*+4*/ UAC_Done_${_UAC.GOIECUniq} ;Admin?
101 StrCmp 3 $1 0 UAC_ElevationAborted_${_UAC.GOIECUniq} ;Try again or abort?
102 MessageBox mb_iconexclamation "${UACSTR.${_modeprefix}ElvMustTryAgain}" ;Inform user...
103 goto UAC_Elevate_${_UAC.GOIECUniq} ;...lets try again
104 UAC_Done_${_UAC.GOIECUniq}:
105 !undef _UAC.GOIECUniq
109 !define UAC.I.Elevate.AdminOnly '!insertmacro UAC.I.Elevate.AdminOnly '
110 !macro UAC.I.Elevate.AdminOnly
111 !insertmacro _UAC.GenerateOnInitElevationCode 'I.'
114 !define UAC.U.Elevate.AdminOnly '!insertmacro UAC.U.Elevate.AdminOnly '
115 !macro UAC.U.Elevate.AdminOnly _UninstallerName
116 !ifNdef UAC_DISABLEUNINSTALLERTANGO
117 !insertmacro _UAC.GenerateUninstallerTango "${_UninstallerName}"
119 !insertmacro _UAC.GenerateOnInitElevationCode 'U.'
122 !define UAC.AutoCodeUnload '!insertmacro UAC.AutoCodeUnload '
123 !macro UAC.AutoCodeUnload _HasUninstaller
124 !insertmacro _UAC.GenerateSimpleFunction "" .OnInstFailed '${UAC.Unload}'
125 !insertmacro _UAC.GenerateSimpleFunction "" .OnInstSuccess '${UAC.Unload}'
127 !insertmacro _UAC.GenerateSimpleFunction "" .onUserAbort '${UAC.Unload}'
129 !ifNdef MUI_CUSTOMFUNCTION_ABORT
130 !error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_ABORT!"
133 !if "${_HasUninstaller}" != ""
134 !insertmacro _UAC.GenerateSimpleFunction "un" .onUninstFailed '${UAC.Unload}'
135 !insertmacro _UAC.GenerateSimpleFunction "un" .onUninstSuccess '${UAC.Unload}'
137 !insertmacro _UAC.GenerateSimpleFunction "un" .onUserAbort '${UAC.Unload}'
139 !ifNdef MUI_CUSTOMFUNCTION_ABORT
140 !error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_(UN)ABORT!"
146 !define UAC.FastCallFunctionAsUser '!insertmacro UAC.FastCallFunctionAsUser '
147 !macro UAC.FastCallFunctionAsUser _func _var
148 GetFunctionAddress ${_var} ${_func}
149 UAC::ExecCodeSegment ${_var}
151 !define UAC.CallFunctionAsUser '!insertmacro UAC.CallFunctionAsUser '
152 !macro UAC.CallFunctionAsUser _func
154 !insertmacro UAC.FastCallFunctionAsUser ${_func} $R9
158 !define UAC.FastCallGetOuterInstanceHwndParent UAC::GetOuterHwnd
159 !define UAC.GetOuterInstanceHwndParent '!insertmacro UAC.GetOuterInstanceHwndParent '
160 !macro UAC.GetOuterInstanceHwndParent _var
162 ${UAC.FastCallGetOuterInstanceHwndParent}
169 !macro _UAC.DumpEx _disp _f _fp _v
171 DetailPrint "${_disp}=${_v}"
173 !macro _UAC.Dump _f _fp _v
174 !insertmacro _UAC.DumpEx `${_f}` `${_f}` `${_fp}` `${_v}`
176 !macro _UAC.DbgDetailPrint
179 System::Call /NoUnload "advapi32::GetUserName(t.r0,*i${NSIS_MAX_STRLEN})"
180 System::Call "Kernel32::GetComputerName(t.r1,*i${NSIS_MAX_STRLEN})"
182 ;!insertmacro _UAC.DumpEx "User" System::Call "advapi32::GetUserName(t.r0,*i${NSIS_MAX_STRLEN})" $0
183 !insertmacro _UAC.DumpEx "CmdLine" "" "" "$CmdLine"
184 !insertmacro _UAC.Dump UAC::IsAdmin "" $0
185 !insertmacro _UAC.Dump UAC::SupportsUAC "" $0
186 !insertmacro _UAC.Dump UAC::GetElevationType "" $0
191 !endif /* ifndef UAC_HDR__INC */