UAC plug-in: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
Line 66: | Line 66: | ||
# 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. Remember to run clean it up with UAC::Unload before your installer exits. Great places to clean it up are un.OnUnInstFailed and un.OnUnInstSuccess | # 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. Remember to run clean it up with UAC::Unload before your installer exits. Great places to clean it up are un.OnUnInstFailed and un.OnUnInstSuccess | ||
# 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 | # 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]]. | ||
===Tested Environments=== | ===Tested Environments=== |
Revision as of 17:48, 11 May 2007
Download & Info
This plug-in attempts to work around the UAC problems on Vista related to starting a new process from an elevated installer.
It all started in http://forums.winamp.com/showthread.php?s=&threadid=265780 and is still very much in the alpha stage (Use at your own risk).
Latest version: UAC v0.0.5e
How it works
Supplying the necessary code
- First, the NSIS script must specify that it should run with user privileges, not admin privileges.
RequestExecutionLevel user /* RequestExecutionLevel REQUIRED! */
- Next, the most common approach is to let the UAC plugin initialize in the .onInit code:
; Attempt to give the UAC plug-in a user process and an admin process. 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: # elevation was aborted, run as normal? 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? MessageBox mb_iconstop "This installer requires admin access, try again" goto UAC_Elevate FunctionEnd
- Before the installer exits, you will need to clean up the plugin. If you don't, it will leave behind a UAC.dll in the user's %TEMP% folder. One easy way to clean it up is by supplying the following:
Function .OnInstFailed UAC::Unload ;Must call unload! FunctionEnd Function .OnInstSuccess UAC::Unload ;Must call unload! FunctionEnd
Remember that if your installer quits before those events can be fired, you should supply a UAC::Unload before the installer quits.
How the UAC plug-in works with user and admin privileges
- When the NSIS installer launches, it calls its .onInit code (no window is visible by this point yet). The UAC plugin makes a new installer process and attempts to elevate it with admin privileges. If needed, a UAC or Run As dialog is shown to help elevate this second process to admin privileges. During this point, if you open up Task Manager, you will see two installer processes running. The user process can be thought of as the outer process, and the admin process the inner process.
- Once elevated, the admin/inner process can display. This is the installer window that users will see.
- Now that you have an admin process, you can continue to let your script do its thing. If you ever need to do something at a user level, you do it through the UAC plugin, and the UAC plugin will run whats needed through the hidden user/outer process. For example, UAC::Exec can execute something with user privileges and not admin privileges. Or UAC::ExecCodeSegment can execute an entire function with user privileges.
Important Notes
- 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. Remember to run clean it up with UAC::Unload before your installer exits. Great places to clean it up are un.OnUnInstFailed and un.OnUnInstSuccess
- 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.
Tested Environments
This plugin has been tested under the following environments:
- Windows Vista - UAC On - Administrator
- Windows Vista - UAC Off - Administrator
- Windows Vista - UAC On - Standard User - User supplies administrator info into the UAC dialog
- Windows Vista - UAC On - Standard User - User does not supply administrator info into the UAC dialog
- Windows Vista - UAC Off - Standard User - User supplies administrator info into the Run As dialog
- Windows Vista - UAC Off - Standard User - User does not supply administrator info into the Run As dialog
- Windows XP - Administrator
- Windows XP - Limited User - User supplies administrator info into the Run As dialog
- Windows XP - Limited User - User does not supply administrator info into the Run As dialog
- Windows 2000 - Administrator
- Windows 2000 - Standard User - User supplies administrator info into the Run As dialog
- Windows 2000 - Standard User - User does not supply administrator info into the Run As dialog
Windows 98 is untested, but it should work. :)