Commit d1638d66 authored by Rafaël Carré's avatar Rafaël Carré

include UAC plugin source code for version 0.0.11.d

modifications by me:
- lower case filenames and includes
- Makefile usable with mingw-w64
- fix compilation with mingw-w64
parent 7262d1c9
History:
--------
v0.0.11d - 20090705 (AndersK)
*Fixed UAC_RealWorldFullyLoadedDualModeExample.nsi so installing as admin will allow both modes
v0.0.11c - 20090124 (AndersK)
*Checks for seclogon service on NT5 and returns ERROR_SERVICE_NOT_ACTIVE in $0 if not running
v0.0.11b - 20090102 (AndersK)
*Fixed unicode compile bugs
v0.0.11 - 20081021 (AndersK)
+Added UAC_GetUserShellFolderPath.nsi (Uses the new UAC::GetShellFolderPath)
v0.0.10a - 20081004 (AndersK)
+Added SEE_MASK_NOZONECHECKS flag (experimental)
v0.0.10 - 20080812 (AndersK)
+Added ugly hook hack to the shells run-as dialog on xp, defaults to other user
v0.0.9 - 20080721 (AndersK)
*Fixed UAC_RealWorldFullyLoadedDualModeExample.nsi related bug (Thanks Case)
v0.0.8 - 20080310 (AndersK)
+HTML Readme
+Added UAC::GetOuterHwnd (used by UAC_RealWorldFullyLoadedDualModeExample.nsi)
*Fixed UAC_RealWorldFullyLoadedDualModeExample.nsi
*Major code cleanup in UAC.cpp
-Removed UAC::RunElevatedAndProcessMessages (UAC::RunElevated now supports non NULL $HWNDParent)
-Removed several useless sample scripts
v0.0.7e - 20080229 (AndersK)
*Added ugly hack for hackwnd to find correct title and give us a proper taskbar so the elevation dialog does not get lost (2000,XP (This also fixed Alt-Tab icon on Vista))
*Should compile with MSVC2005 now (Thanks Case)
*More unicode fixes, this time even tested with NSIS Unicode (Only RunElevated and Exec tested)
v0.0.7d - 20080226 (AndersK)
*Fixed a couple of unicode version bugs (Unicode version still untested)
*Fixed weird XP string length bug (Thanks kfank)
v0.0.7c - 20080218 (AndersK)
*Fixed SyncVars string length bug
v0.0.7b - 20080205 (AndersK)
*Fixed DelayLoadDlls() problem on NT4
v0.0.7 - 20080120 (AndersK)
+Added UAC::StackPush (For use with ExecCodeSegment)
v0.0.6d - 20071108 (AndersK)
+Now syncs basic registers/variables before calling UAC::*Exec* and UAC::ExecCodeSegment (r0-r9,R0-R9,$CMDLINE,$INSTDIR,$OUTDIR,$EXEDIR,$LANGUAGE)
+Added UAC::RunElevatedAndProcessMessages, this can be called after .onInit (Very experimental, DO NOT USE)
+New include file with helper macros: UAC.nsh
*Replazed Clammerz hack with a better version
v0.0.6c - 20071014 (AndersK)
+Check for and split up "domain\user" style input in RunAs.cpp for CreateProcessWithLogonW
*Added a ugly hack to trick messagebox'es in .OnInit to appear correctly on Vista (Thanks Clammerz)
v0.0.6b - 20070523 (AndersK)
*Fixed showwindow flag (Thanks for the help kichik)
v0.0.6 - 20070512 (AndersK)
+Added basic language support for MyRunAs dialog.
v0.0.5e - 20070509 (AndersK)
*Fixed detection of UAC mode?
+IPC window is visible (but offscreen) during elevation to help with SetForegroundWindow/Focus problems
v0.0.5d - 20070324 (AndersK)
*Fixed stupid IsAdmin bug
v0.0.5c - 20070304 (AndersK)
*_IsAdmin now uses CheckTokenMembership if it exists ( MSKB:Q118626 / http://blogs.msdn.com/larryosterman/archive/2007/03/14/why-does-kb-118626-use-accesscheck-to-check-if-you-re-a-member-of-the-administrators-group.aspx )
v0.0.5b - 20070301 (AndersK)
*Fixed ExecCodeSegment (Thread now calls CoInitialize)
v0.0.5 - 20070228 (AndersK)
+Added ExecCodeSegment (You can now call ANY code in the context of the original user)
v0.0.4b - 20070226 (AndersK)
*Fixed (My)RunAs font (http://blogs.msdn.com/oldnewthing/archive/2005/02/04/366987.aspx)
v0.0.4 - 20070225 (AndersK)
+Added (My)RunAs dialog, used on Vista when running as LUA with UAC off
+Always uses /NCRC for elevated instance
*Now compiles as UNICODE (Untested, no UnicodeNSIS to test on)
v0.0.3 - 20070224 (AndersK)
+Added Exec/ExecWait
+Added Verb & ShowWindow support for ShellExec[Wait]
v0.0.2 - 20070219 (AndersK)
+Added ShellExecWait
*IPC srv wnd now has its own thread and msg loop
*Removed CRT dependency
*Hopefully loads on Win95 now
v0.0.1 - 20070215 (AndersK)
*Initial release
\ No newline at end of file
This software is provided 'as-is', without any express or implied warranty.
ZLIB/LIBPNG LICENSE
-------------------
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
\ No newline at end of file
This diff is collapsed.
/*
=======================
UAC helper include file
.......................
Macros starting with UAC.I should only be called from the installer and vice versa for UAC.U macros.
*/
!ifndef UAC_HDR__INC
!define UAC_HDR__INC
!include LogicLib.nsh
!define UAC.RunElevatedAndProcessMessages 'UAC::RunElevated '
!define UAC.Unload 'UAC::Unload '
!define UAC.StackPush 'UAC::StackPush '
/*!macro _UAC.BuildOnInitElevationFunc _funcprefix
Function ${_funcprefix}onInit
!ifmacrodef
FunctionEnd
!macroend*/
!macro _UAC.GenerateSimpleFunction _funcprefix _funcName _funcCode
Function ${_funcprefix}${_funcName}
${_funcCode}
#messagebox mb_ok "${_funcprefix}${_funcName}"
FunctionEnd
!macroend
!macro _UAC.TryDef _d _v
!ifndef ${_d}
!define ${_d} "${_v}"
!endif
!macroend
!macro _UAC.InitStrings _modeprefix
!insertmacro _UAC.TryDef UACSTR.UnDataFile "UAC.dat"
!insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvWinErr "Unable to elevate , error $0"
!ifNdef __UNINSTALL__
!insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvAbortReqAdmin "This installer requires admin access, aborting!"
!insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvMustTryAgain "This installer requires admin access, try again"
!else
!insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvAbortReqAdmin "This uninstaller requires admin access, aborting!"
!insertmacro _UAC.TryDef UACSTR.${_modeprefix}ElvMustTryAgain "This uninstaller requires admin access, try again"
!endif
!macroend
!ifmacroNdef _UAC.GenerateUninstallerTango
!macro _UAC.GenerateUninstallerTango UninstallerFileName
!ifdef __GLOBAL__
!error "UAC: Needs to be called inside a function"
!endif
!ifNdef __UNINSTALL__
!error "UAC: _UAC.GenerateUninstallerTango should only be called by uninstaller, see http://forums.winamp.com/showthread.php?threadid=280330"
!endif
!ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
!include WinVer.nsh
!endif
!insertmacro _UAC.InitStrings 'U.'
ReadIniStr $0 "$ExeDir\${UACSTR.UnDataFile}" UAC "Un.Ready"
${IF} $0 != 1
!ifNdef UAC_UNINSTALLERTANGOFORALLPLATFORMS
${AndIf} ${AtLeastWinVista}
!endif
InitPluginsDir
WriteIniStr "$PluginsDir\${UACSTR.UnDataFile}" UAC "Un.Ready" 1
CopyFiles /SILENT "$EXEPATH" "$PluginsDir\${UninstallerFileName}"
StrCpy $0 ""
${IfThen} ${Silent} ${|} StrCpy $0 "/S " ${|}
ExecWait '"$PluginsDir\${UninstallerFileName}" $0/NCRC _?=$INSTDIR' $0
SetErrorLevel $0
Quit
${EndIf}
!macroend
!endif
!ifmacroNdef _UAC.GenerateOnInitElevationCode
!macro _UAC.GenerateOnInitElevationCode _modeprefix
!ifndef __FUNCTION__
!error "UAC: Needs to be called inside a function"
!endif
!insertmacro _UAC.InitStrings ${_modeprefix}
!define _UAC.GOIECUniq L${__LINE__}
UAC_Elevate_${_UAC.GOIECUniq}:
UAC::RunElevated
StrCmp 1223 $0 UAC_ElevationAborted_${_UAC.GOIECUniq} ; UAC dialog aborted by user?
StrCmp 0 $0 0 UAC_Err_${_UAC.GOIECUniq} ; Error?
StrCmp 1 $1 0 UAC_Success_${_UAC.GOIECUniq} ;Are we the real deal or just the wrapper?
Quit
UAC_Err_${_UAC.GOIECUniq}:
MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvWinErr}"
Abort
UAC_ElevationAborted_${_UAC.GOIECUniq}:
MessageBox mb_iconstop "${UACSTR.${_modeprefix}ElvAbortReqAdmin}"
Abort
UAC_Success_${_UAC.GOIECUniq}:
# if $0==0 && $3==1, we are a member of the admin group (Any OS)
# if $0==0 && $1==0, UAC not supported (Probably <NT6), run as normal?
# if $0==0 && $1==3, we can try to elevate again
StrCmp 1 $3 /*+4*/ UAC_Done_${_UAC.GOIECUniq} ;Admin?
StrCmp 3 $1 0 UAC_ElevationAborted_${_UAC.GOIECUniq} ;Try again or abort?
MessageBox mb_iconexclamation "${UACSTR.${_modeprefix}ElvMustTryAgain}" ;Inform user...
goto UAC_Elevate_${_UAC.GOIECUniq} ;...lets try again
UAC_Done_${_UAC.GOIECUniq}:
!undef _UAC.GOIECUniq
!macroend
!endif
!define UAC.I.Elevate.AdminOnly '!insertmacro UAC.I.Elevate.AdminOnly '
!macro UAC.I.Elevate.AdminOnly
!insertmacro _UAC.GenerateOnInitElevationCode 'I.'
!macroend
!define UAC.U.Elevate.AdminOnly '!insertmacro UAC.U.Elevate.AdminOnly '
!macro UAC.U.Elevate.AdminOnly _UninstallerName
!ifNdef UAC_DISABLEUNINSTALLERTANGO
!insertmacro _UAC.GenerateUninstallerTango "${_UninstallerName}"
!endif
!insertmacro _UAC.GenerateOnInitElevationCode 'U.'
!macroend
!define UAC.AutoCodeUnload '!insertmacro UAC.AutoCodeUnload '
!macro UAC.AutoCodeUnload _HasUninstaller
!insertmacro _UAC.GenerateSimpleFunction "" .OnInstFailed '${UAC.Unload}'
!insertmacro _UAC.GenerateSimpleFunction "" .OnInstSuccess '${UAC.Unload}'
!ifNdef MUI_INCLUDED
!insertmacro _UAC.GenerateSimpleFunction "" .onUserAbort '${UAC.Unload}'
!else
!ifNdef MUI_CUSTOMFUNCTION_ABORT
!error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_ABORT!"
!endif
!endif
!if "${_HasUninstaller}" != ""
!insertmacro _UAC.GenerateSimpleFunction "un" .onUninstFailed '${UAC.Unload}'
!insertmacro _UAC.GenerateSimpleFunction "un" .onUninstSuccess '${UAC.Unload}'
!ifNdef MUI_INCLUDED
!insertmacro _UAC.GenerateSimpleFunction "un" .onUserAbort '${UAC.Unload}'
!else
!ifNdef MUI_CUSTOMFUNCTION_ABORT
!error "UAC: must call $$ {UAC.Unload} in MUI_CUSTOMFUNCTION_(UN)ABORT!"
!endif
!endif
!endif
!macroend
!define UAC.FastCallFunctionAsUser '!insertmacro UAC.FastCallFunctionAsUser '
!macro UAC.FastCallFunctionAsUser _func _var
GetFunctionAddress ${_var} ${_func}
UAC::ExecCodeSegment ${_var}
!macroend
!define UAC.CallFunctionAsUser '!insertmacro UAC.CallFunctionAsUser '
!macro UAC.CallFunctionAsUser _func
push $R9
!insertmacro UAC.FastCallFunctionAsUser ${_func} $R9
pop $R9
!macroend
!define UAC.FastCallGetOuterInstanceHwndParent UAC::GetOuterHwnd
!define UAC.GetOuterInstanceHwndParent '!insertmacro UAC.GetOuterInstanceHwndParent '
!macro UAC.GetOuterInstanceHwndParent _var
push $0
${UAC.FastCallGetOuterInstanceHwndParent}
Exch $0
Pop ${_var}
!macroend
!macro _UAC.DumpEx _disp _f _fp _v
${_f} ${_fp}
DetailPrint "${_disp}=${_v}"
!macroend
!macro _UAC.Dump _f _fp _v
!insertmacro _UAC.DumpEx `${_f}` `${_f}` `${_fp}` `${_v}`
!macroend
!macro _UAC.DbgDetailPrint
push $0
push $1
System::Call /NoUnload "advapi32::GetUserName(t.r0,*i${NSIS_MAX_STRLEN})"
System::Call "Kernel32::GetComputerName(t.r1,*i${NSIS_MAX_STRLEN})"
DetailPrint "$1\$0"
;!insertmacro _UAC.DumpEx "User" System::Call "advapi32::GetUserName(t.r0,*i${NSIS_MAX_STRLEN})" $0
!insertmacro _UAC.DumpEx "CmdLine" "" "" "$CmdLine"
!insertmacro _UAC.Dump UAC::IsAdmin "" $0
!insertmacro _UAC.Dump UAC::SupportsUAC "" $0
!insertmacro _UAC.Dump UAC::GetElevationType "" $0
pop $1
pop $0
!macroend
!endif /* ifndef UAC_HDR__INC */
\ No newline at end of file
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
!define APPNAME "UAC_AdminOnly"
Name "${APPNAME}"
OutFile "${APPNAME}.exe"
ShowInstDetails show
!include UAC.nsh ;<<< New headerfile that does everything for you ;)
!include LogicLib.nsh
!define UACSTR.I.ElvAbortReqAdmin "This fancy app requires admin rights fool" ;custom error string, see _UAC.InitStrings macro in uac.nsh for more
Function .OnInit
${UAC.I.Elevate.AdminOnly}
FunctionEnd
Function .OnInstFailed
${UAC.Unload}
FunctionEnd
Function .OnInstSuccess
${UAC.Unload}
FunctionEnd
Function ExecCodeSegmentTest
${If} "$1" != "666, the # of the beast"
MessageBox mb_ok "uh oh"
${EndIf}
FunctionEnd
Section "Info"
!insertmacro _UAC.DbgDetailPrint
StrCpy $1 "666, the # of the beast"
!insertmacro UAC.CallFunctionAsUser ExecCodeSegmentTest
SectionEnd
page InstFiles
/* LEGACY CODE: (now uses magic code from UAC.nsh)
Function .OnInit
UAC_Elevate:
UAC::RunElevated
StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp 0 $0 0 UAC_Err ; Error?
StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quit
UAC_Err:
MessageBox mb_iconstop "Unable to elevate , error $0"
Abort
UAC_ElevationAborted:
/*System::Call "user32::CreateWindowEx(i ${WS_EX_TRANSPARENT}|${WS_EX_LAYERED}, t 'Button', t 'blah', i 0, i 10, i 10, i 10, i 10, i 0, i 0, i 0) i .r0"
ShowWindow $0 ${SW_SHOW}
System::Call "user32::SetForegroundWindow(i r0) i."
System::Call "user32::DestroyWindow(i r0) i."
* /
MessageBox mb_iconstop "This installer requires admin access, aborting!"
Abort
UAC_Success:
StrCmp 1 $3 +4 ;Admin?
StrCmp 3 $1 0 UAC_ElevationAborted ;Try again or abort?
MessageBox mb_iconstop "This installer requires admin access, try again" ;Inform user...
goto UAC_Elevate ;... and try again
FunctionEnd*/
\ No newline at end of file
/*
This sample will try to elevate, but it will also allow non admin users to continue if they click cancel in the elevation dialog
*/
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
!define APPNAME "UAC_AllowLUA"
Name "${APPNAME}"
OutFile "${APPNAME}.exe"
ShowInstDetails show
!include UAC.nsh
Function .OnInstFailed
UAC::Unload ;Must call unload!
FunctionEnd
Function .OnInstSuccess
UAC::Unload ;Must call unload!
FunctionEnd
Function .OnInit
UAC::RunElevated
;MessageBox mb_iconinformation "Debug: UAC::RunElevated: $\n0(Error)=$0 $\n1(UACMode)=$1 $\n2=$2 $\nadmin=$3$\n$\n$CmdLine"
StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp 0 $0 0 UAC_Err ; Error?
StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quit
UAC_Err:
MessageBox mb_iconstop "Unable to elevate , error $0"
Abort
UAC_ElevationAborted:
# elevation was aborted, we still run as normal
UAC_Success:
FunctionEnd
Section "Info"
!insertmacro _UAC.DbgDetailPrint
SectionEnd
Page InstFiles
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
!define APPNAME "UAC_GetUserShellFolderPath"
Name "${APPNAME}"
OutFile "${APPNAME}.exe"
ShowInstDetails show
!include UAC.nsh
!include LogicLib.nsh
page instfiles
Function .onInit
${UAC.I.Elevate.AdminOnly}
FunctionEnd
!ifndef CSIDL_PERSONAL
!define CSIDL_PERSONAL 0x0005 ;My Documents
!endif
Section
/*
You can specify a fallback value in the 2nd parameter, it is used if the installer is not elevated
or running on NT4/Win9x or on errors.
If you just want to check for success, use "" as the 2nd parameter and compare $0 with ""
*/
UAC::GetShellFolderPath ${CSIDL_PERSONAL} $Documents
DetailPrint MyDocs=$0
SectionEnd
/*
This sample supports two modes, installing as a normal user (single user install) AND as admin (all users install)
This sample uses the registry plugin, so you need to download that if you don't already have it
*/
!define APPNAME "UAC_RealWorldFullyLoadedDualMode"
!define ELEVATIONTITLE "${APPNAME}: Elevate" ;displayed during elevation on our custom page
!define SMSUBDIR $StartMenuFolder ;"${APPNAME}"
!define UNINSTALLER_NAME "Uninstall ${APPNAME}.exe"
!define UNINSTALLER_REGSECTION "${APPNAME}"
!define RegPath.MSUninstall "Software\Microsoft\Windows\CurrentVersion\Uninstall"
Name "${APPNAME}"
OutFile "${APPNAME}.exe"
ShowInstDetails show
SetCompressor LZMA
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
!include MUI.nsh
!include UAC.nsh
!include LogicLib.nsh
!include Registry.nsh
!include nsDialogs.nsh ;for our custom page
!include FileFunc.nsh ;we need to parse the command line
!insertmacro GetParameters
!insertmacro GetOptions
!define MUI_CUSTOMFUNCTION_ABORT onAbort
!define MUI_CUSTOMFUNCTION_GUIINIT onGuiInit
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\llama-blue.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\llama-blue.ico"
!define MUI_WELCOMEPAGE_TITLE_3LINES
var InstMode # 0: Single user, 1:All users, >1:elevated instance, perform page jump
var hKey # Reg hive
var hSelModeAdminRadio
var StartMenuFolder
!macro SetMode IsAdmin
!if "${IsAdmin}" > 0
SetShellVarContext all
StrCpy $InstMode 1
StrCpy $hKey HKLM
!else
SetShellVarContext current
StrCpy $InstMode 0
StrCpy $hKey HKCU
!endif
!macroend
Function .OnInit
!insertmacro SetMode 0
${GetParameters} $R9
${GetOptions} "$R9" UAC $0 ;look for special /UAC:???? parameter (sort of undocumented)
${Unless} ${Errors}
UAC::IsAdmin
${If} $0 < 1
SetErrorLevel 666 ;special return value for outer instance so it knows we did not have admin rights
Quit
${EndIf}
!insertmacro SetMode 1
StrCpy $InstMode 2
${EndIf}
FunctionEnd
Function onGuiInit
${If} $InstMode >= 2
${UAC.GetOuterInstanceHwndParent} $0
${If} $0 <> 0
System::Call /NOUNLOAD "*(i,i,i,i)i.r1"
System::Call /NOUNLOAD 'user32::GetWindowRect(i $0,i r1)i.r2'
${If} $2 <> 0
System::Call /NOUNLOAD "*$1(i.r2,i.r3)"
System::Call /NOUNLOAD 'user32::SetWindowPos(i $hwndParent,i0,ir2,ir3,i0,i0,i 4|1)'
${EndIf}
ShowWindow $hwndParent ${SW_SHOW}
ShowWindow $0 ${SW_HIDE} ;hide outer instance installer window
System::Free $1
${EndIf}
${EndIf}
FunctionEnd
Function Un.OnInit
!insertmacro SetMode 0
ReadRegDWORD $0 HKLM "${RegPath.MSUninstall}\${UNINSTALLER_REGSECTION}" InstMode ;We saved the "mode" in the installer
${If} $0 U> 0
; If it was installed for all users, we have to be admin to uninstall it
${UAC.U.Elevate.AdminOnly} "${UNINSTALLER_NAME}"
!insertmacro SetMode 1
${EndIf}
FunctionEnd
Function onAbort
${UAC.Unload}
FunctionEnd
${UAC.AutoCodeUnload} 1 ;Auto-generate .OnInstFailed and .OnInstSuccess functions
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPageInElvModePreCB
!insertmacro MUI_PAGE_WELCOME
Page Custom ModeSelectionPageCreate ModeSelectionPageLeave
!define MUI_PAGE_CUSTOMFUNCTION_PRE CmpntsPreCB
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE DirPreCB
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU 1 $StartMenuFolder
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_TITLE_3LINES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION FinishRunCB
!insertmacro MUI_PAGE_FINISH
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function CmpntsPreCB
GetDlgItem $0 $hwndparent 3
${IfThen} $InstMode >= 1 ${|} EnableWindow $0 0 ${|} ;prevent user from going back and selecting single user so noobs don't end up installing as the wrong user
FunctionEnd
Function SkipPageInElvModePreCB
${IfThen} $InstMode > 1 ${|} Abort ${|} ;skip this page so we get to the mode selection page
FunctionEnd
Function ModeSelectionPageCreate
${If} $InstMode > 1
StrCpy $InstMode 1
Abort ;skip this page and contine where the "parent" would have gone
${EndIf}
!insertmacro MUI_HEADER_TEXT_PAGE "Select install type" "Blah blah blah blah"
nsDialogs::Create /NOUNLOAD 1018
Pop $0
${NSD_CreateLabel} 0 20u 75% 20u "Blah blah blah blah select install type..."
Pop $0
System::Call "advapi32::GetUserName(t.r0, *i ${NSIS_MAX_STRLEN}r1) i.r2"
${NSD_CreateRadioButton} 0 40u 75% 15u "Single User ($0)"
Pop $0
${IfThen} $InstMode U< 1 ${|} SendMessage $0 ${BM_SETCHECK} 1 0 ${|}
${NSD_CreateRadioButton} 0 60u 75% 15u "All users"
Pop $hSelModeAdminRadio
${IfThen} $InstMode U> 0 ${|} SendMessage $hSelModeAdminRadio ${BM_SETCHECK} 1 0 ${|}
nsDialogs::Show
FunctionEnd
!macro EnableCtrl dlg id state
push $language
GetDlgItem $language ${dlg} ${id}
EnableWindow $language ${state}
pop $language
!macroend
Function ModeSelectionPageLeave
SendMessage $hSelModeAdminRadio ${BM_GETCHECK} 0 0 $9
UAC::IsAdmin
${If} $9 U> 0
${If} $0 <> 0
!insertmacro SetMode 1
${Else}
System::Call /NoUnload 'user32::GetWindowText(i $HwndParent,t.R1,i ${NSIS_MAX_STRLEN})' ;get original window title
System::Call /NoUnload 'user32::SetWindowText(i $HwndParent,t "${ELEVATIONTITLE}")' ;set out special title
StrCpy $2 "" ;reset special return, only gets set when sub process is executed, not when user cancels
!insertmacro EnableCtrl $HWNDParent 1 0 ;Disable next button, just because it looks good ;)
${UAC.RunElevatedAndProcessMessages}
!insertmacro EnableCtrl $HWNDParent 1 1
System::Call 'user32::SetWindowText(i $HwndParent,t "$R1")' ;restore title
${If} $2 = 666 ;our special return, the new process was not admin after all
MessageBox mb_iconExclamation "You need to login with an account that is a member of the admin group to continue..."
Abort
${ElseIf} $0 = 1223 ;cancel
Abort
${Else}
${If} $0 <> 0
${If} $0 = 1062
MessageBox mb_iconstop "Unable to elevate, Secondary Logon service not running!"
${Else}
MessageBox mb_iconstop "Unable to elevate, error $0 ($1,$2,$3)"
${EndIf}
Abort
${EndIf}
${EndIf}
Quit ;We now have a new process, the install will continue there, we have nothing left to do here
${EndIf}
${EndIf}
FunctionEnd
Function DirPreCB
${If} $InstDir == ""
${If} $InstMode U> 0
StrCpy $InstDir "$ProgramFiles\${APPNAME}"
${Else}
StrCpy $InstDir "$APPDATA\${APPNAME}"
${EndIf}
${EndIf}
FunctionEnd
Function FinishRunCB
UAC::Exec "" "Notepad.exe" "$Windir\Win.INI" "$InstDir"
FunctionEnd
Function CreateSMShortcuts
StrCpy ${SMSUBDIR} $9 ;stupid sync
CreateDirectory "$SMPrograms\${SMSUBDIR}"
CreateShortcut "$SMPrograms\${SMSUBDIR}\${APPNAME}.lnk" "$Windir\Notepad.exe"
CreateShortcut "$SMPrograms\${SMSUBDIR}\Uninstall ${APPNAME}.lnk" "$InstDir\${UNINSTALLER_NAME}"
FunctionEnd
Function CreateDeskShortcuts
CreateShortcut "$Desktop\${APPNAME}.lnk" "$Windir\Notepad.exe"
FunctionEnd
Section "!Required files"
SectionIn RO
SetOutPath -
!insertmacro _UAC.DbgDetailPrint ;some debug info, useful during testing
;Install files here...
WriteUninstaller "$InstDir\${UNINSTALLER_NAME}"
${registry::Write} "$hKey\${RegPath.MSUninstall}\${UNINSTALLER_REGSECTION}" DisplayName "${APPNAME}" REG_SZ $0
${registry::Write} "$hKey\${RegPath.MSUninstall}\${UNINSTALLER_REGSECTION}" UninstallString "$InstDir\${UNINSTALLER_NAME}" REG_SZ $0
${registry::Write} "$hKey\${RegPath.MSUninstall}\${UNINSTALLER_REGSECTION}" InstMode $InstMode REG_DWORD $0
${registry::Unload}
SectionEnd
Section "Startmenu Shortcuts"
StrCpy $9 ${SMSUBDIR} ;this is stupid as hell, we need correct ${SMSUBDIR} in the outer process, this is the only way (plugins cannot enum "custom" var's AFAIK)
${UAC.CallFunctionAsUser} CreateSMShortcuts
SectionEnd
Section "Desktop Shortcut"
${UAC.CallFunctionAsUser} CreateDeskShortcuts
SectionEnd
Section Uninstall
Delete "$InstDir\${UNINSTALLER_NAME}"
Delete "$SMPrograms\${SMSUBDIR}\${APPNAME}.lnk"
Delete "$SMPrograms\${SMSUBDIR}\Uninstall ${APPNAME}.lnk"
RMDir "$SMPrograms\${SMSUBDIR}"
Delete "$Desktop\${APPNAME}.lnk"
RMDir "$InstDir"
${registry::DeleteKey} "$hKey\${RegPath.MSUninstall}\${UNINSTALLER_REGSECTION}" $0
${registry::Unload}
SectionEnd
\ No newline at end of file
/*
This script was made in response to http://forums.winamp.com/showthread.php?threadid=280330
It is a ugly hack and is mostly here just to have a solution right now.
Hopefully, NSIS will add support for changing the RequestExecutionLevel of the uninstaller
This code inspired the _UAC.GenerateUninstallerTango macro (called by ${UAC.U.Elevate.AdminOnly} unless you define UAC_DISABLEUNINSTALLERTANGO)
*/
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
!define APPNAME "UAC_Uninstaller"
Name "${APPNAME}"
OutFile "${APPNAME}.exe"
ShowInstDetails show
!include LogicLib.nsh
!define UNINSTALLER_UACDATA "uac.ini"
!define UNINSTALLER_NAME "Uninstall FooBarBaz"
Function un.onInit
ReadIniStr $0 "$ExeDir\${UNINSTALLER_UACDATA}" UAC "Un.First"
${IF} $0 != 1
;SetSilent silent
InitPluginsDir
WriteIniStr "$PluginsDir\${UNINSTALLER_UACDATA}" UAC "Un.First" 1
CopyFiles /SILENT "$EXEPATH" "$PluginsDir\${UNINSTALLER_NAME}.exe"
StrCpy $0 ""
${IfThen} ${Silent} ${|} StrCpy $0 "/S " ${|}
ExecWait '"$PluginsDir\${UNINSTALLER_NAME}.exe" $0/NCRC _?=$INSTDIR' $0
SetErrorLevel $0
Quit
${EndIf}
# UAC code goes here ...
FunctionEnd
Section
WriteUninstaller "$exedir\${UNINSTALLER_NAME}.exe"
SetAutoClose true
DetailPrint "Uninstalling..."
Sleep 1111
Exec '"$exedir\${UNINSTALLER_NAME}.exe"'
SectionEnd
Section uninstall
MessageBox mb_ok "My filename is: $EXEFILE"
Delete "$instdir\${UNINSTALLER_NAME}.exe"
Delete "$instdir\${APPNAME}.exe" ;delete generated installer aswell, this is just a sample script
SectionEnd
page InstFiles
\ No newline at end of file
/*
Alternative to ExDll.h
v0.0.1 - 20060811 (AndersK)
*/
#pragma once
#include <tchar.h>
typedef TCHAR NSISCH;
#define NSISCALL __stdcall
namespace NSIS {
__forceinline void* NSISCALL MemAlloc(SIZE_T cb) {return GlobalAlloc(LPTR,cb);}
__forceinline void NSISCALL MemFree(void* p) {GlobalFree(p);}
enum {
INST_0, // $0
INST_1, // $1
INST_2, // $2
INST_3, // $3
INST_4, // $4
INST_5, // $5
INST_6, // $6
INST_7, // $7
INST_8, // $8
INST_9, // $9
INST_R0, // $R0
INST_R1, // $R1
INST_R2, // $R2
INST_R3, // $R3
INST_R4, // $R4
INST_R5, // $R5
INST_R6, // $R6
INST_R7, // $R7
INST_R8, // $R8
INST_R9, // $R9
INST_CMDLINE, // $CMDLINE
INST_INSTDIR, // $INSTDIR
INST_OUTDIR, // $OUTDIR
INST_EXEDIR, // $EXEDIR
INST_LANG, // $LANGUAGE
__INST_LAST,
VIDX_TEMP=(INST_LANG+1), //#define state_temp_dir g_usrvars[25]
VIDX_PLUGINSDIR,//# define state_plugins_dir g_usrvars[26]
VIDX_EXEPATH,//#define state_exe_path g_usrvars[27]
VIDX_EXEFILENAME,//#define state_exe_file g_usrvars[28]
VIDX_STATECLICKNEXT,//#define state_click_next g_usrvars[30]
__VIDX_UNDOCLAST
};
typedef struct _stack_t {
struct _stack_t *next;
NSISCH text[ANYSIZE_ARRAY];
} stack_t;
typedef struct {
int autoclose;
int all_user_var;
int exec_error;
int abort;
int exec_reboot;
int reboot_called;
int XXX_cur_insttype; // deprecated
int XXX_insttype_changed; // deprecated
int silent;
int instdir_error;
int rtl;
int errlvl;
//NSIS v2.3x ?
int alter_reg_view;
int status_update;
} exec_flags_type;
typedef struct {
exec_flags_type *exec_flags;
int (NSISCALL *ExecuteCodeSegment)(int, HWND);
void (NSISCALL *validate_filename)(char *);
} extra_parameters;
extern UINT StrSize;
extern stack_t **StackTop;
extern NSISCH*Vars;
inline bool NSISCALL SetErrLvl(extra_parameters*pExtraParams,int ErrLevel) {return pExtraParams? ((pExtraParams->exec_flags->errlvl=ErrLevel)||true):false;}
inline bool NSISCALL SetErrorFlag(extra_parameters*pExtraParams) {return pExtraParams? ((pExtraParams->exec_flags->exec_error=1)||true):false;}
inline bool NSISCALL ClearErrorFlag(extra_parameters*pExtraParams) {return pExtraParams?((pExtraParams->exec_flags->exec_error=0)||true):false;}
__forceinline int NSISCALL ExecuteCodeSegment(extra_parameters*pExtraParams,int pos,HWND hwndProgress=NULL) {
return pExtraParams?pExtraParams->ExecuteCodeSegment(pos,hwndProgress):(/*EXEC_ERROR*/0x7FFFFFFF);
}
static NSISCH* __fastcall GetVar(const int varnum)
{
//ASSERT(NSIS::Vars && NSIS::StrSize);
if (varnum < 0 || varnum >= __VIDX_UNDOCLAST) return NULL;
return NSIS::Vars+(varnum*NSIS::StrSize);
}
inline void NSISCALL SetVarUINT(const int varnum,UINT Value) {
wsprintf(GetVar(varnum),_T("%u"),Value);
}
static stack_t* NSISCALL StackPop() {
if (NSIS::StackTop && *NSIS::StackTop) {
stack_t*s=(*NSIS::StackTop);
*NSIS::StackTop=(*NSIS::StackTop)->next;
return s;
}
return 0;
}
__forceinline void NSISCALL StackFreeItem(stack_t*pStackItem) {NSIS::MemFree(pStackItem);}
static DWORD NSISCALL StackPush(NSISCH*InStr,UINT StackStrSize=NSIS::StrSize) {
if (!NSIS::StackTop)return ERROR_INVALID_PARAMETER;
stack_t*sNew=(stack_t*)NSIS::MemAlloc(sizeof(stack_t)+(StackStrSize*sizeof(NSISCH)));
if (!sNew)return ERROR_OUTOFMEMORY;
lstrcpyn(sNew->text,InStr,StackStrSize);
sNew->next=*NSIS::StackTop;
*NSIS::StackTop=sNew;
return NO_ERROR;
}
}; /* namespace */
#define NSISUTIL_INIT() namespace NSIS {UINT StrSize;stack_t **StackTop;NSISCH*Vars;}//Call in only ONE source file
#define NSISUTIL_INITEXPORT(_v,_strsize,_stackt) NSIS::Vars=_v;NSIS::StrSize=_strsize;NSIS::StackTop=_stackt
//#define NSISEXPORT4(_func,_h,_strsize,_v,_stackt) extern "C" void __declspec(dllexport) __cdecl \
// _func (HWND _h,int _strsize,NSISCH*_v,NSIS::stack_t **_stackt) { NSISUTIL_INITEXPORT(_v,_strsize,_stackt); TRACE("EXPORT::" #_func "\n");
//#define NSISEXPORT5(_func,_h,_strsize,_v,_stackt,_eparams) extern "C" void __declspec(dllexport) __cdecl \
// _func (HWND _h,int _strsize,NSISCH*_v,NSIS::stack_t **_stackt,NSIS::extra_parameters* _eparams) { NSISUTIL_INITEXPORT(_v,_strsize,_stackt); TRACE("EXPORT::" #_func "\n");
//#define NSISEXPORT NSISEXPORT5
#define EXPORTNSISFUNC extern "C" void __declspec(dllexport) __cdecl
#define NSISFUNCSTART4(_h,_strsize,_v,_stackt) {NSISUTIL_INITEXPORT(_v,_strsize,_stackt);
#define NSISFUNCSTART5(_h,_strsize,_v,_stackt,_eparams) NSISFUNCSTART4(_h,_strsize,_v,_stackt)
#define NSISFUNCSTART NSISFUNCSTART5
#define NSISFUNCEND() }
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
#define IDD_MYRUNAS 101
#define IDC_RUNASCURR 1000
#define IDC_RUNASSPEC 1001
#define IDC_SHICON 1002
#define IDC_HELPTEXT 1003
#define IDC_USERNAME 1004
#define IDC_PASSWORD 1005
#define IDC_LBLUSER 1007
#define IDC_LBLPWD 1008
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1009
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
#include "uac.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MYRUNAS DIALOG DISCARDABLE 0, 0, 250, 145
STYLE DS_MODALFRAME | DS_NOIDLEMSG | DS_SETFOREGROUND | DS_FIXEDSYS |
DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "&OK",IDOK,132,122,50,14
PUSHBUTTON "Ca&ncel",IDCANCEL,188,122,50,14
ICON "",IDC_SHICON,7,7,20,20
LTEXT "",IDC_HELPTEXT,34,7,204,35
CONTROL "",IDC_RUNASCURR,"Button",BS_AUTORADIOBUTTON,20,49,218,
10
CONTROL "",IDC_RUNASSPEC,"Button",BS_AUTORADIOBUTTON,20,65,218,
10
LTEXT "&User name:",IDC_LBLUSER,20,84,42,16
EDITTEXT IDC_USERNAME,63,83,175,14,ES_AUTOHSCROLL
LTEXT "&Password:",IDC_LBLPWD,20,102,42,20
EDITTEXT IDC_PASSWORD,63,100,175,14,ES_PASSWORD | ES_AUTOHSCROLL
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_MYRUNAS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 238
TOPMARGIN, 7
BOTTOMMARGIN, 136
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""uac.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
This diff is collapsed.
This diff is collapsed.
//Copyright (C) 2007 Anders Kjersem. Licensed under the zlib/libpng license, see License.txt for details.
#pragma once
/** /#define BUILD_DBGRELEASE // Include simple debug output in release version */
/** /#define BUILD_DBGSELECTELVMODE //Test MyRunAs*/
/** /#define UNICODE // Unicode build */
/**/#define FEAT_CUSTOMRUNASDLG // Include custom runas dialog */
/**/#define FEAT_CUSTOMRUNASDLG_TRANSLATE //*/
/**/#define FEAT_MSRUNASDLGMODHACK // Default to other user radio button */
#if !defined(APSTUDIO_INVOKED) && !defined(RC_INVOKED)
#if (defined(_MSC_VER) && !defined(_DEBUG))
#pragma comment(linker,"/opt:nowin98")
#pragma comment(linker,"/ignore:4078")
#pragma comment(linker,"/merge:.rdata=.text")
//#pragma intrinsic(memset) //http://www.codeguru.com/forum/showthread.php?t=371491&page=2&pp=15 | http://www.ddj.com/windows/184416623
#endif
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#endif
#ifdef _UNICODE
#define TFUNCSUFFIX W
#else
#define TFUNCSUFFIX A
#endif
#define _PCJOIN(a,b) a##b
#define PCJOIN(a,b) _PCJOIN(a,b)
#define _WIN32_WINNT 0x0501
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#include <tchar.h>
#include "nsisutil.h"
#ifndef SEE_MASK_NOZONECHECKS
#define SEE_MASK_NOZONECHECKS 0x00800000
#endif
#define COUNTOF(___c) ( sizeof(___c)/sizeof(___c[0]) )
#ifndef ARRAYSIZE
#define ARRAYSIZE COUNTOF
#endif
#if _MSC_VER >= 1400
extern void* __cdecl memset(void*mem,int c,size_t len);
#endif
FORCEINLINE LRESULT MySndDlgItemMsg(HWND hDlg,int id,UINT Msg,WPARAM wp=0,LPARAM lp=0) {return SendMessage(GetDlgItem(hDlg,id),Msg,wp,lp);}
#ifndef UAC_NOCUSTOMIMPLEMENTATIONS
FORCEINLINE HANDLE WINAPI GetCurrentProcess(){return ((HANDLE)(-1));}
FORCEINLINE HANDLE WINAPI GetCurrentThread(){return ((HANDLE)(-2));}
#define MyTStrLen lstrlen
#undef lstrcpy
#define lstrcpy MyTStrCpy
FORCEINLINE LPTSTR MyTStrCpy(LPTSTR s1,LPCTSTR s2) {return PCJOIN(lstr,PCJOIN(cpyn,TFUNCSUFFIX))(s1,s2,0x7FFFFFFF);}
#undef lstrcat
#define lstrcat MyTStrCat
LPTSTR MyTStrCat(LPTSTR s1,LPCTSTR s2)
#ifdef UAC_INITIMPORTS
{return s1?MyTStrCpy(&s1[MyTStrLen(s1)],s2):NULL;}
#else
;
#endif //UAC_INITIMPORTS
#endif //UAC_NOCUSTOMIMPLEMENTATIONS
//DelayLoaded functions:
typedef BOOL (WINAPI*ALLOWSETFOREGROUNDWINDOW)(DWORD dwProcessId);
typedef BOOL (WINAPI*OPENPROCESSTOKEN)(HANDLE ProcessHandle,DWORD DesiredAccess,PHANDLE TokenHandle);
typedef BOOL (WINAPI*OPENTHREADTOKEN)(HANDLE ThreadHandle,DWORD DesiredAccess,BOOL OpenAsSelf,PHANDLE TokenHandle);
typedef BOOL (WINAPI*GETTOKENINFORMATION)(HANDLE hToken,TOKEN_INFORMATION_CLASS TokInfoClass,LPVOID TokInfo,DWORD TokInfoLenh,PDWORD RetLen);
typedef BOOL (WINAPI*ALLOCATEANDINITIALIZESID)(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,BYTE nSubAuthorityCount,DWORD sa0,DWORD sa1,DWORD sa2,DWORD sa3,DWORD sa4,DWORD sa5,DWORD sa6,DWORD sa7,PSID*pSid);
typedef PVOID (WINAPI*FREESID)(PSID pSid);
typedef BOOL (WINAPI*EQUALSID)(PSID pSid1,PSID pSid2);
typedef BOOL (WINAPI*CHECKTOKENMEMBERSHIP)(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember);
#ifdef FEAT_CUSTOMRUNASDLG
typedef BOOL (WINAPI*GETUSERNAME)(LPTSTR lpBuffer,LPDWORD nSize);
typedef BOOL (WINAPI*CREATEPROCESSWITHLOGONW)(LPCWSTR lpUsername,LPCWSTR lpDomain,LPCWSTR lpPassword,DWORD dwLogonFlags,LPCWSTR lpApplicationName,LPWSTR lpCommandLine,DWORD dwCreationFlags,LPVOID pEnv,LPCWSTR WorkDir,LPSTARTUPINFOW pSI,LPPROCESS_INFORMATION pPI);
#define SECURITY_WIN32
#include <security.h>//namesamcompatible
typedef BOOLEAN (WINAPI*GETUSERNAMEEX)(EXTENDED_NAME_FORMAT NameFormat,LPTSTR lpNameBuffer,PULONG nSize);
#endif
#ifdef UAC_INITIMPORTS
ALLOWSETFOREGROUNDWINDOW _AllowSetForegroundWindow=0;
OPENPROCESSTOKEN _OpenProcessToken=0;
OPENTHREADTOKEN _OpenThreadToken=0;
GETTOKENINFORMATION _GetTokenInformation=0;
ALLOCATEANDINITIALIZESID _AllocateAndInitializeSid=0;
FREESID _FreeSid=0;
EQUALSID _EqualSid=0;
CHECKTOKENMEMBERSHIP _CheckTokenMembership=0;
#ifdef FEAT_CUSTOMRUNASDLG
GETUSERNAME _GetUserName=0;
GETUSERNAMEEX _GetUserNameEx=0;
CREATEPROCESSWITHLOGONW _CreateProcessWithLogonW=0;
#endif
#else
#ifdef FEAT_CUSTOMRUNASDLG
extern GETUSERNAME _GetUserName;
extern GETUSERNAMEEX _GetUserNameEx;
extern CREATEPROCESSWITHLOGONW _CreateProcessWithLogonW;
#endif
#endif /* UAC_INITIMPORTS */
extern DWORD DelayLoadDlls();
#ifdef FEAT_CUSTOMRUNASDLG
extern DWORD MyRunAs(HINSTANCE hInstDll,SHELLEXECUTEINFO&sei);
#endif
#if !defined(NTDDI_VISTA) || defined(BUILD_OLDSDK)
//#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < 0x06000000) || !defined(NTDDI_VISTA)
//#if !defined(TOKEN_ELEVATION_TYPE) || defined(BUILD_OLDSDK)
enum TOKEN_ELEVATION_TYPE {
TokenElevationTypeDefault = 1,
TokenElevationTypeFull,
TokenElevationTypeLimited
};
enum _TOKEN_INFORMATION_CLASS___VISTA {
TokenElevationType = (TokenOrigin+1),
TokenLinkedToken,
TokenElevation,
TokenHasRestrictions,
TokenAccessInformation,
TokenVirtualizationAllowed,
TokenVirtualizationEnabled,
TokenIntegrityLevel,
TokenUIAccess,
TokenMandatoryPolicy,
TokenLogonSid,
};
#endif
#if defined(_DEBUG) || defined(BUILD_DBGRELEASE)
//Simple debug helpers:
#define BUILD_DBG
/** /#define BUILD_XPTEST //Pretend UAC exists and "elevate" with NT runas */
#define DBG_RESETDBGVIEW() do{HWND hDbgView=FindWindowA("dbgviewClass",0);PostMessage(hDbgView,WM_COMMAND,40020,0);if(0)SetForegroundWindow(hDbgView);}while(0)
#define _pp_MakeStr_(x) #x
#define pp_MakeStr(x) _pp_MakeStr_(x)
#define TRACE OutputDebugStringA
#define DBGONLY(_x) _x
#ifndef ASSERT
#define ASSERT(_x) do{if(!(_x)){MessageBoxA(GetActiveWindow(),#_x##"\n\n"##__FILE__##":"## pp_MakeStr(__LINE__),"SimpleAssert",0);/*TRACE(#_x##"\n"##__FILE__##":" pp_MakeStr(__LINE__)"\n");*/}}while(0)
#endif
#define VERIFY(_x) ASSERT(_x)
static void TRACEF(const char*fmt,...) {va_list a;va_start(a,fmt);static TCHAR b[1024*4];if (sizeof(TCHAR)!=sizeof(char)){static TCHAR fmtBuf[COUNTOF(b)];VERIFY(wsprintf(fmtBuf,_T("%hs"),fmt)<COUNTOF(fmtBuf));fmt=(LPCSTR)fmtBuf;}wvsprintf(b,(TCHAR*)fmt,a);OutputDebugString(b);}
#else
#define TRACE /*(void)0*/
#define DBGONLY(_x)
#define ASSERT(_x)
#define VERIFY(_x) ((void)(_x))
#define TRACEF TRACE
#endif /* DEBUG */
#endif /* APSTUDIO_INVOKED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment