UAC plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(added documentation link)
(→‎Info: Added link)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{PageAuthor|Anders}}
{{PageAuthor|Anders}}
[[Category:Plugins]]
[[Category:Plugins]]
[[Category:Deprecated]]
<div style="border: 1px solid #404000; background-color:#FFFF80; color:#000; padding:0.5em;"><b>Note:</b>This plug-in is deprecated. It started out as a proof of concept in the early Vista days and should now be considered abandoned.</div>




==Plugin Info==
==Plugin Info==
* '''Version:''' 0.2.3c (20110920)
* '''Version:''' 0.2.4c (20150526)
* '''Type:''' Runtime plugin
* '''Type:''' Runtime plugin
* '''Character encoding:''' Ansi
* '''Character encoding:''' Ansi
* '''Minimum OS:''' Win95/NT4 (Elevation on Win2000+)
* '''Minimum OS:''' Win95/NT4 (Elevation on Win2000+)
* '''Minimum NSIS Version:''' 2.45
* '''Minimum NSIS Version:''' 2.45
* '''License:''' Freeware
* '''License:''' zlib
* '''Download:''' <attach>UAC.zip</attach>
* '''Download:''' <attach>UAC.zip</attach>




==Info==
==Info==
This plug-in attempts to work around UAC installation problems on Win2000+.  This plug-in allows your installer to operate with a user level process and an admin level process.  This allows you to accomplish things that would otherwise be very difficult.  For example, you can have a elevated installer instance launch another process as the user.
This plug-in attempts to work around UAC installation problems on Win2000+.  This plug-in allows your installer to operate with a user level process and an admin level process ([https://docs.microsoft.com/en-us/windows/win32/secauthz/administrator-broker-model administrator broker model]).  This allows you to accomplish things that would otherwise be very difficult.  For example, you can have an elevated installer instance launch another process as the user.


It all started in [http://forums.winamp.com/showthread.php?s=&threadid=265780 this thread].  It has been field tested with good results.  It is still definitely in the beta stage (i.e. use at your own risk).
It all started in [http://forums.winamp.com/showthread.php?s=&threadid=265780 this thread].  It has been field tested with good results.  It is still definitely in the beta stage (i.e. use at your own risk).


==Basic Example==
==Basic Example==
Line 53: Line 55:
Quit
Quit
${Default}
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate , error $0"
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
Quit
Quit
${EndSwitch}
${EndSwitch}
Line 99: Line 101:
SectionEnd
SectionEnd
</highlight-nsis>
</highlight-nsis>
==Function Call Documentation==
Here's a link to some documentation (no idea if this is the latest or not): http://autobuilder.yoctoproject.org/sources/hg/hg.mozilla.org/incubator/offscreen/other-licenses/nsis/Contrib/UAC/UAC%20Readme.html
Here are some other documented function calls that have been found on the forums:
# UAC::ShellExec <STR:Verb> <INT:ShowWindow> <STR:App> <STR:Parameters> <STR:WorkingDir>
# UAC::ExecWait <INT:ShowWindow> <STR:App> <STR:Parameters> <STR:WorkingDir>


==Important Notes==
==Important Notes==
Line 113: Line 106:
# The outer/user process does not display any output as to what occurred.  For example, if you have the outer/user process create a shortcut, and it fails, the inner/admin process currently visible will not display anything to indicate that a problem occurred.  This is because the outer/user process does not yet communicate back to the inner/admin process.
# The outer/user process does not display any output as to what occurred.  For example, if you have the outer/user process create a shortcut, and it fails, the inner/admin process currently visible will not display anything to indicate that a problem occurred.  This is because the outer/user process does not yet communicate back to the inner/admin process.
# When a standard or limited user supplies administrator information into the Run As dialog, you may experience permissions trouble with any extracted file.  For example, if a Windows 2000 standard user supplies administrator info into the Run As dialog, and the NSIS installer extracts an .exe file, then trying to call that .exe through an Exec can fail.  If this is a problem, you will want to use the [[AccessControl_plug-in|AccessControl plug-in]].
# When a standard or limited user supplies administrator information into the Run As dialog, you may experience permissions trouble with any extracted file.  For example, if a Windows 2000 standard user supplies administrator info into the Run As dialog, and the NSIS installer extracts an .exe file, then trying to call that .exe through an Exec can fail.  If this is a problem, you will want to use the [[AccessControl_plug-in|AccessControl plug-in]].
==More helpful notes==
I'm not good at reading .nsi files so I simplified things even more to understand just part of what this plugin can do.  First of all put the UAC.dll into the NSIS/Plugins folder and you are supposed to put UAC.nsh into the NSIS/Include/ folder (but you don't have to for my example).
<highlight-nsis>
Function .onInit
;!insertmacro UAC_RunElevated
UAC::_ 0  ;this does the same thing as the line above but the line above needs to include uac.nsh
;$0=1223        means user said 'no' so we are at user level
;$0=0 $1=3      user chose to run as non-admin in run-as... dialog (similar to 1223)
;$0=0 $1=2 $3=1 we are admin now
;$0=0 $1=1      we are original (outer) non-admin process but the inner admin process completed
MessageBox mb_TopMost|mb_SetForeground "zero has $0 one has $1 three has $3"
quit
FunctionEnd
</highlight-nsis>
If you add only the above code to your installer you can run it many times from different operating systems and as admin, non-admin on vista, on xp and see the different behaviors.  It makes things so much clearer.
There are other cool things this plugin can do.  If you have tested them out please add more to this wiki page.

Latest revision as of 14:32, 21 January 2022

Author: Anders (talk, contrib)


Note:This plug-in is deprecated. It started out as a proof of concept in the early Vista days and should now be considered abandoned.


Plugin Info

  • Version: 0.2.4c (20150526)
  • Type: Runtime plugin
  • Character encoding: Ansi
  • Minimum OS: Win95/NT4 (Elevation on Win2000+)
  • Minimum NSIS Version: 2.45
  • License: zlib
  • Download: UAC.zip (50 KB)


Info

This plug-in attempts to work around UAC installation problems on Win2000+. This plug-in allows your installer to operate with a user level process and an admin level process (administrator broker model). This allows you to accomplish things that would otherwise be very difficult. For example, you can have an elevated installer instance launch another process as the user.

It all started in this thread. It has been field tested with good results. It is still definitely in the beta stage (i.e. use at your own risk).

Basic Example

/*
Basic script for a all users/shared installer.
It runs the installed application as the correct user...
*/
 
!define S_NAME "UAC_Basic example"
Name "${S_NAME}"
OutFile "${S_NAME}.exe"
RequestExecutionLevel user ; << Required, you cannot use admin!
InstallDir "$ProgramFiles\${S_NAME}"
 
!include MUI2.nsh
!include UAC.nsh
 
!macro Init thing
uac_tryagain:
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
	${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
	${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
	${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
		MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, try again" /SD IDNO IDYES uac_tryagain IDNO 0
	${EndIf}
	;fall-through and die
${Case} 1223
	MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, aborting!"
	Quit
${Case} 1062
	MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Logon service not running, aborting!"
	Quit
${Default}
	MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
	Quit
${EndSwitch}
 
SetShellVarContext all
!macroend
 
Function .onInit
!insertmacro Init "installer"
FunctionEnd
 
Function un.onInit
!insertmacro Init "uninstaller"
FunctionEnd
 
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION PageFinishRun
!insertmacro MUI_PAGE_FINISH
 
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
 
!insertmacro MUI_LANGUAGE "English"
 
 
Function PageFinishRun
; You would run "$InstDir\MyApp.exe" here but this example has no application to execute...
!insertmacro UAC_AsUser_ExecShell "" "$WinDir\notepad.exe" "" "" ""
FunctionEnd
 
Section
SetOutPath $InstDir
# TODO: File "MyApp.exe"
WriteUninstaller "$InstDir\Uninstall.exe"
SectionEnd
 
Section Uninstall
SetOutPath $Temp ; Make sure $InstDir is not the current directory so we can remove it
# TODO: Delete "$InstDir\MyApp.exe"
Delete "$InstDir\Uninstall.exe"
RMDir "$InstDir"
SectionEnd

Important Notes

  1. If you need to use the UAC plugin for the uninstaller as well, you will need to initalize the UAC plugin for the uninstaller, such as through un.onInit.
  2. The outer/user process does not display any output as to what occurred. For example, if you have the outer/user process create a shortcut, and it fails, the inner/admin process currently visible will not display anything to indicate that a problem occurred. This is because the outer/user process does not yet communicate back to the inner/admin process.
  3. When a standard or limited user supplies administrator information into the Run As dialog, you may experience permissions trouble with any extracted file. For example, if a Windows 2000 standard user supplies administrator info into the Run As dialog, and the NSIS installer extracts an .exe file, then trying to call that .exe through an Exec can fail. If this is a problem, you will want to use the AccessControl plug-in.