PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

/admin/win/nsi/nsis_uac/UAC.nsh

http://github.com/tomahawk-player/tomahawk
Unknown | 191 lines | 173 code | 18 blank | 0 comment | 0 complexity | 0a37adcbd9452e5869266bba42150bf4 MD5 | raw file
  1/*
  2=======================
  3UAC helper include file
  4.......................
  5
  6Macros starting with UAC.I should only be called from the installer and vice versa for UAC.U macros.
  7
  8*/
  9!ifndef UAC_HDR__INC
 10!define UAC_HDR__INC
 11!include LogicLib.nsh
 12
 13!define UAC.RunElevatedAndProcessMessages 'UAC::RunElevated '
 14!define UAC.Unload 'UAC::Unload '
 15!define UAC.StackPush 'UAC::StackPush '
 16
 17/*!macro _UAC.BuildOnInitElevationFunc _funcprefix
 18Function ${_funcprefix}onInit
 19!ifmacrodef
 20FunctionEnd
 21!macroend*/
 22
 23!macro _UAC.GenerateSimpleFunction _funcprefix _funcName _funcCode
 24Function ${_funcprefix}${_funcName}
 25${_funcCode}
 26#messagebox mb_ok "${_funcprefix}${_funcName}"
 27FunctionEnd
 28!macroend
 29
 30!macro _UAC.TryDef _d _v
 31!ifndef ${_d}
 32!define ${_d} "${_v}"
 33!endif
 34!macroend
 35
 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"
 39!ifNdef __UNINSTALL__
 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"
 42	!else
 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"
 45	!endif
 46!macroend
 47
 48!ifmacroNdef _UAC.GenerateUninstallerTango
 49!macro _UAC.GenerateUninstallerTango UninstallerFileName
 50!ifdef __GLOBAL__
 51	!error "UAC: Needs to be called inside a function"
 52	!endif
 53!ifNdef __UNINSTALL__
 54	!error "UAC: _UAC.GenerateUninstallerTango should only be called by uninstaller, see http://forums.winamp.com/showthread.php?threadid=280330"
 55	!endif
 56!ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
 57	!include WinVer.nsh
 58	!endif
 59!insertmacro _UAC.InitStrings 'U.'
 60ReadIniStr $0 "$ExeDir\${UACSTR.UnDataFile}" UAC "Un.Ready"
 61${IF} $0 != 1
 62!ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
 63${AndIf} ${AtLeastWinVista}
 64!endif
 65	InitPluginsDir
 66	WriteIniStr "$PluginsDir\${UACSTR.UnDataFile}" UAC "Un.Ready" 1
 67	CopyFiles /SILENT "$EXEPATH" "$PluginsDir\${UninstallerFileName}"
 68	StrCpy $0 ""
 69	${IfThen} ${Silent} ${|} StrCpy $0 "/S " ${|}
 70	ExecWait '"$PluginsDir\${UninstallerFileName}" $0/NCRC _?=$INSTDIR' $0
 71	SetErrorLevel $0
 72	Quit
 73	${EndIf}
 74!macroend
 75!endif
 76
 77!ifmacroNdef _UAC.GenerateOnInitElevationCode
 78!macro _UAC.GenerateOnInitElevationCode _modeprefix
 79!ifndef __FUNCTION__
 80	!error "UAC: Needs to be called inside a function"
 81	!endif
 82!insertmacro _UAC.InitStrings ${_modeprefix}
 83!define _UAC.GOIECUniq L${__LINE__}
 84UAC_Elevate_${_UAC.GOIECUniq}:
 85UAC::RunElevated 
 86StrCmp 1223 $0 UAC_ElevationAborted_${_UAC.GOIECUniq} ; UAC dialog aborted by user?
 87StrCmp 0 $0 0 UAC_Err_${_UAC.GOIECUniq} ; Error?
 88StrCmp 1 $1 0 UAC_Success_${_UAC.GOIECUniq} ;Are we the real deal or just the wrapper?
 89Quit
 90UAC_Err_${_UAC.GOIECUniq}:
 91MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvWinErr}"
 92Abort
 93UAC_ElevationAborted_${_UAC.GOIECUniq}:
 94MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvAbortReqAdmin}"
 95Abort
 96UAC_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
100StrCmp 1 $3 /*+4*/ UAC_Done_${_UAC.GOIECUniq} ;Admin?
101StrCmp 3 $1 0 UAC_ElevationAborted_${_UAC.GOIECUniq} ;Try again or abort?
102MessageBox mb_iconexclamation "${UACSTR.${_modeprefix}ElvMustTryAgain}" ;Inform user...
103goto UAC_Elevate_${_UAC.GOIECUniq} ;...lets try again
104UAC_Done_${_UAC.GOIECUniq}:
105!undef _UAC.GOIECUniq
106!macroend
107!endif
108
109!define UAC.I.Elevate.AdminOnly '!insertmacro UAC.I.Elevate.AdminOnly '
110!macro UAC.I.Elevate.AdminOnly
111!insertmacro _UAC.GenerateOnInitElevationCode 'I.'
112!macroend
113
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}"
118	!endif
119!insertmacro _UAC.GenerateOnInitElevationCode 'U.'
120!macroend
121
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}'
126!ifNdef MUI_INCLUDED
127	!insertmacro _UAC.GenerateSimpleFunction "" .onUserAbort '${UAC.Unload}'
128	!else
129	!ifNdef MUI_CUSTOMFUNCTION_ABORT
130		!error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_ABORT!"
131		!endif
132	!endif
133!if "${_HasUninstaller}" != ""
134	!insertmacro _UAC.GenerateSimpleFunction "un" .onUninstFailed '${UAC.Unload}'
135	!insertmacro _UAC.GenerateSimpleFunction "un" .onUninstSuccess '${UAC.Unload}'
136	!ifNdef MUI_INCLUDED
137		!insertmacro _UAC.GenerateSimpleFunction "un" .onUserAbort '${UAC.Unload}'
138		!else
139		!ifNdef MUI_CUSTOMFUNCTION_ABORT
140			!error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_(UN)ABORT!"
141			!endif
142		!endif
143	!endif
144!macroend
145
146!define UAC.FastCallFunctionAsUser '!insertmacro UAC.FastCallFunctionAsUser '
147!macro UAC.FastCallFunctionAsUser _func _var
148GetFunctionAddress ${_var} ${_func}
149UAC::ExecCodeSegment ${_var}
150!macroend
151!define UAC.CallFunctionAsUser '!insertmacro UAC.CallFunctionAsUser '
152!macro UAC.CallFunctionAsUser _func
153push $R9
154!insertmacro UAC.FastCallFunctionAsUser ${_func} $R9
155pop $R9
156!macroend
157
158!define UAC.FastCallGetOuterInstanceHwndParent UAC::GetOuterHwnd
159!define UAC.GetOuterInstanceHwndParent '!insertmacro UAC.GetOuterInstanceHwndParent '
160!macro UAC.GetOuterInstanceHwndParent _var
161push $0
162${UAC.FastCallGetOuterInstanceHwndParent}
163Exch $0
164Pop ${_var}
165!macroend
166
167
168
169!macro _UAC.DumpEx _disp _f _fp _v
170${_f} ${_fp}
171DetailPrint "${_disp}=${_v}"
172!macroend
173!macro _UAC.Dump _f _fp _v
174!insertmacro _UAC.DumpEx `${_f}` `${_f}` `${_fp}` `${_v}`
175!macroend
176!macro _UAC.DbgDetailPrint
177push $0
178push $1
179System::Call /NoUnload "advapi32::GetUserName(t.r0,*i${NSIS_MAX_STRLEN})"
180System::Call "Kernel32::GetComputerName(t.r1,*i${NSIS_MAX_STRLEN})"
181DetailPrint "$1\$0"
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
187pop $1
188pop $0
189!macroend
190
191!endif /* ifndef UAC_HDR__INC */