UAC plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Reverted edits by 88.182.150.129 to last version by Anders)
Line 2: Line 2:


[[Category:Plugins]]
[[Category:Plugins]]
Télécharger == == & Info
==Download & Info==
Ce plug-in tentatives de contourner les problèmes d'installation sur Vista UAC / 7. Ce plug-in permet à votre installateur pour fonctionner avec un processus de niveau utilisateur et un processus de niveau administrateur. Cela vous permet d'accomplir des choses qui seraient autrement très difficile. Par exemple, vous pouvez avoir un niveau installateur admin lancer un autre processus au niveau utilisateur. Ou vous pouvez avoir un niveau installateur admin créer des raccourcis au niveau utilisateur.
This plug-in attempts to work around UAC installation problems on Vista/7. 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 an admin level installer launch another process at a user level. Or you can have an admin level installer create shortcuts at a user level.


Tout a commencé en [http://forums.winamp.com/showthread.php?s=&threadid=265780 ce fil]. Il a été testé sur le terrain avec de bons résultats. Il est encore nettement au stade bêta (c.-à-utiliser à vos risques et périls).
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).


branche courante: [% http://stashbox.org/988128/UAC% 20v0.2.2c 20 - 2020100828.zip% v0.2.2c]
Current branch: [http://stashbox.org/988128/UAC%20v0.2.2c%20-%2020100828.zip v0.2.2c]


branche vieillesse: [20v0.0.11d.zip% http://stashbox.org/560965/UAC v0.0.11d]
Old branch: [http://stashbox.org/560965/UAC%20v0.0.11d.zip v0.0.11d]


<font color=red NOTE red;display:block;"> style="border:2px solides: Tout le code sur cette page s'applique à l'ancienne version, la syntaxe a changé légèrement de 0,2 et vous devez utiliser les macros dans uac.nsh </ font>
<font color=red style="border:2px solid red;display:block;">NOTE: All code on this page applies to the older version, the syntax has changed slightly for 0.2 and you should use the macros in uac.nsh</font>


=== === L'installation de base
===Basic installation===
Pour installer le plugin UAC dans votre configuration NSIS, il vous suffit de copier deux fichiers ZIP de ce qui précède:
To install the UAC plugin in your NSIS setup, you just need to copy two files from the above ZIP:


* Pour les installateurs ANSI,'''UAC.nsh''copier dans votre répertoire d'inclusion (par exemple C: \ Program Files \ NSIS \ Include) et'''''UAC.dll chez sortie / A dans votre répertoire de plugins ( par exemple C: \ Program Files \ NSIS \ Plugins).
* For ANSI installers, copy '''UAC.nsh''' into your Include directory (e.g. C:\Program Files\NSIS\Include) and '''UAC.dll''' from Release/A into your Plugins directory (e.g. C:\Program Files\NSIS\Plugins).


* Pour les installateurs Unicode,'''UAC.nsh''copier dans votre répertoire d'inclusion (par exemple C: \ Program Files \ NSIS \ Unicode \ Include) et'''''UAC.dll chez sortie / U dans votre Plugins répertoire (par exemple C: \ Program Files \ NSIS \ Unicode \ Plugins).
* For Unicode installers, copy '''UAC.nsh''' into your Include directory (e.g. C:\Program Files\NSIS\Unicode\Include) and '''UAC.dll''' from Release/U into your Plugins directory (e.g. C:\Program Files\NSIS\Unicode\Plugins).


=== === Comment ça marche?
===How it works===


Nécessaire ==== ==== Fournir le code
====Supplying the necessary code====
* Tout d'Abord, le script NSIS DOIT fonctionner devrait preciser qu'il Itinéraires des privilèges d'Utilisateur, et non des pas des privilèges d'administrateur.
* First, the NSIS script must specify that it should run with user privileges, not admin privileges.


<highlight-nsis>
<highlight-nsis>
Utilisateur RequestExecutionLevel / * RequestExecutionLevel compte tenu des adaptations! * /
RequestExecutionLevel user    /* RequestExecutionLevel REQUIRED! */
</ Highlight-nsis>
</highlight-nsis>
* Ensuite, l'Approche commune la plus intérêt de laisser l'UAC plugin initialisateur onInit DANS code le.:
* Next, the most common approach is to let the UAC plugin initialize in the .onInit code:
<highlight-nsis>
<highlight-nsis>
; Tenter de Donner l'UAC plug-in d'Utilisateur non Processus et Processus de l'ONU d'admin.
; Attempt to give the UAC plug-in a user process and an admin process.
Fonction. OnInit
Function .OnInit


UAC_Elevate:
UAC_Elevate:
UAC:: RunElevated
    UAC::RunElevated  
StrCmp 1223 0 $ UAC_ElevationAborted; de dialogue interrompu par l'Utilisateur UAC?
    StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp 0 0 0 $ UAC_Err; Erreur?
    StrCmp 0 $0 0 UAC_Err ; Error?
StrCmp 1 1 0 $ UAC_Success; Sommes-nous de La Vraie affaire ous Tout simplement l'enveloppe?
    StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quitter
    Quit
 
   
UAC_Err:
UAC_Err:
MB_ICONSTOP MessageBox "Impossible d'elever, d'Erreur $ 0"
    MessageBox mb_iconstop "Unable to elevate, error $0"
Avorter
    Abort


UAC_ElevationAborted:
UAC_ElevationAborted:
# Élévation une Abandonnée Été, ordinary fonctionner?
    # elevation was aborted, run as normal?
MessageBox MB_ICONSTOP «Ce programme d'installation requiert Accès non admin, abandonner!"
    MessageBox mb_iconstop "This installer requires admin access, aborting!"
Avorter
    Abort


UAC_Success:
UAC_Success:
StrCmp 1 3 4 $; Admin?
    StrCmp 1 $3 +4 ;Admin?
StrCmp 3 1 0 $ UAC_ElevationAborted; Essayez à nouveau?
    StrCmp 3 $1 0 UAC_ElevationAborted ;Try again?
MessageBox MB_ICONSTOP «Ce programme d'installation requiert Accès non admin, à essayer nouveau"
    MessageBox mb_iconstop "This installer requires admin access, try again"
goto UAC_Elevate
    goto UAC_Elevate  
 
   
FunctionEnd
FunctionEnd
</ Highlight-nsis>
</highlight-nsis>
* Avant la sortie d'installation, Vous devrez Nettoyer le plugin. Pas si n'avez vous, il laissera Derrière Lui UNE UAC.dll en% de l'Utilisateur dossier TEMP%. Un Moyen facile de s'égoutter les Dégâts intérêt en fournissant le texte précédent:
* 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:
<highlight-nsis>
<highlight-nsis>
Fonction. OnInstFailed
Function .OnInstFailed
UAC:: Décharger; décharger appeler liard!
    UAC::Unload ;Must call unload!
FunctionEnd
FunctionEnd


Fonction. OnInstSuccess
Function .OnInstSuccess
UAC:: Décharger; décharger appeler liard!
    UAC::Unload ;Must call unload!
FunctionEnd
FunctionEnd
</ Highlight-nsis>
</highlight-nsis>
Que Rappelez-vous si l'installation Votre soi avant au Québec ferme CES Événements déclenchés may être, Vous Devez fournir UNE UAC:: avant décharger le programme d'installation se ferme.
Remember that if your installer quits before those events can be fired, you should supply a UAC::Unload before the installer quits.


==== Comment l'UAC plug-in fonctionne Itinéraires des privilèges d'Utilisateur et admin ====
====How the UAC plug-in works with user and admin privileges====
* Lorsque le programme d'installation NSIS lance, il une des privilèges d'Utilisateur (tél. nominale specified Que l'Utilisateur RequestExecutionLevel). Immédiatement, l'installateur NSIS onInit Appelle code fils .. (Note, Fenêtre Aucune n'est Encore visible stade CE A). L'UAC plugin Përmet non Processus de''deuxième''installateur et tente de l'elever Itinéraires des privilèges admin. Nécessaire Si, ous l'ONU UAC Executer en important au Québec boîte de dialogue s'affiche de verser secouriste à elever CE Deuxième Processus Itinéraires des privilèges admin. CE un stade, si Vous ouvrez le Gestionnaire des Tâches, Vous verrez Deux Processus en cours d'installation. Le Processus Utilisateur may être de considére Comme le Processus externe, et le Processus de admin le Processus interne.
* When the NSIS installer launches, it has user privileges (as specified by RequestExecutionLevel user). Immediately, the NSIS installer calls its .onInit code. (Note, no window is visible yet at this point). The UAC plugin makes a ''second'' 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 with admin privileges. At 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.
* Une Fois eleves, l'admin / s'affiche Processus interne. C'Est La Fenêtre d'installation au Québec les users verront.
* Once elevated, the admin/inner process will display. This is the installer window that users will see.
* Maintenant Que Vous AVEZ Processus non admin, continuateur pouvez laisser script Vous à Votre faire SA a choisi. Si Jamais Vous AVEZ Besoin de faire journey au Niveau Utilisateur, Vous le FAITES par l'UAC plugin, et l'UAC plugin whats fonctionnera Nécessaire par l'Utilisateur invisible / externe Processus. Par exemple, l'UAC:: Quelque Exec exécuteur may choisi Itinéraires des privilèges d'Utilisateur et non des pas des privilèges d'administrateur. Ou UAC:: Peut ExecCodeSegment exécuteur Fonction UNE AVEC Entière les privilèges Utilisateur.
* 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.


Exemples === ===
===Examples===
NOTE''<font color="red">: syntaxe une DANS Changé 0,2 alphas, Tout sur la page this utiliser la> vieille syntaxe'''</ police
<font color="red">'''NOTE: Syntax has changed in 0.2 alphas, everything on this page uses the old syntax'''</font>


De nombreux exemples se vendor Dans Le fichier. zip ci-Dessus. Si Vous Voulez UNE Meilleure idée de la CE au Québec CE plugin may faire, CES étudier "exemples. Un bref Aperçu de Deux exemples simples sont «donnés ici:
Many examples are found in the .zip file above. If you want a better idea of what this plugin can do, study those examples. A brief overview of two simple examples are given here:
==== Création d'Utilisateur non Raccourci ====
====Creating a user shortcut====


NE UAC_RealWorldExample.nsi:
UAC_RealWorldExample.nsi does:


<highlight-nsis>
<highlight-nsis>
CreateShortcuts Fonction
Function CreateShortcuts
CreateShortcut "lnk $ Desktop \ $ {APPNAME}." "$ Windir \ Notepad.exe"
  CreateShortcut "$Desktop\${APPNAME}.lnk" "$Windir\Notepad.exe"
FunctionEnd
FunctionEnd


«Raccourci bureau» Section
Section "Desktop Shortcut"
GetFunctionAddress $ 0 CreateShortcuts
  GetFunctionAddress $0 CreateShortcuts
UAC:: ExecCodeSegment 0 $
  UAC::ExecCodeSegment $0
SectionEnd
SectionEnd
</ Highlight-INS>
</highlight-nsis>


Par exemple CET Dan, voulons UNO exécuteur la Fonction CreateShortcuts AVEC les privilèges Utilisateur, may il Fait how are exchange rates non Utilisateur au Niveau Raccourci. Fait, PREMIÈREMENT, definir la Fonction. Ensuite, utilisez GetFunctionAddress verser Obtenir l'adresse Fonction of this. Ensuite, Appelez UAC: au ExecCodeSegment demandeuse de Processus externe Utilisateur / pour Fonction this exécuteur. Comme la Fonction sérums executé au Niveau Utilisateur, il Raccourci how are exchange rates va verser l'ONU au Québec plutot Utilisateur versez l'administrateur.
In this example, we would want to run the CreateShortcuts function with user privileges, so it can create a user-level shortcut. So first, define the function.   Then use GetFunctionAddress to get the address of that function. Then, call UAC::ExecCodeSegment to ask the outer/user process to run that function.   Since the function will be run at a user level, it will create a shortcut for the user instead of for the administrator.


==== Lancement d'Une application Itinéraires des privilèges Utilisateur ====
====Launching an application with user privileges====
<highlight-nsis>
<highlight-nsis>
;! Insertmacro UAC_AsUser_ExecShell <Command> <Fichier> <Paramètres> <WorkingDir> <ShowWindow>
; !insertmacro UAC_AsUser_ExecShell <Command> <File> <Parameters> <WorkingDir> <ShowWindow>
! $ «Ouverte» insertmacro UAC_AsUser_ExecShell INSTDIR \ $ {} APPFILE '-FirstRun' $ INSTDIR'''
!insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\${APPFILE}' '-firstrun' '$INSTDIR' ''
</ Highlight-nsis>
</highlight-nsis>


Lorsque $ INSTDIR \ $ {} CEST APPFILE le chemin vers le fichier au Québec Vous souhaitez lancer.
Where $INSTDIR\${APPFILE} is the path to the file you want to launch.


Si Vous utilisez la peau et le MUI Lancement d'installation de l'application Pour Vous, Vous aurez Besoin PEU faire verser des Nations Unies ainsi que de Travail.
If you use the MUI skin and have the installer launch the app for you, you will need to do a little more work.


<highlight-nsis>
<highlight-nsis>
! Definir MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN
! ExecAppFile MUI_FINISHPAGE_RUN_FUNCTION Definir
!define MUI_FINISHPAGE_RUN_FUNCTION ExecAppFile


Fonction ExecAppFile
Function ExecAppFile  
! $ «Ouverte» insertmacro UAC_AsUser_ExecShell INSTDIR \ $ {} APPFILE '-FirstRun' $ INSTDIR'''
    !insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\${APPFILE}' '-firstrun' '$INSTDIR' ''
FunctionEnd
FunctionEnd
</ Highlight-nsis>
</highlight-nsis>


Gardez à l'esprit Que Vous AVEZ Encore definir à MUI_FINISHPAGE_RUN (vide Comme) Sinon Pas MUI NE fournira l'option à Tous.
Keep in mind that you still have to define MUI_FINISHPAGE_RUN (as empty) otherwise MUI won't provide the option at all.


=== === IMPORTANTES Notes
===Important Notes===


# Besoin Si AVEZ Vous d'utiliser »l'UAC Plugin pour le programme de désinstallation, Ainsi, Besoin d'initialisateur Vous aurez l'UAC Plugin pour le programme de désinstallation, un.onInit nominale comme. Pas d'N'oubliez exécuteur le s'égoutter AVEC l'UAC:: décharger avant Votre sortie de désinstallation. Bonnes adresses versez sont Nettoyer le un.OnUnInstFailed un.OnUnInstSuccess et
# 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 uninstaller exits. Great places to clean it up are un.OnUnInstFailed and un.OnUnInstSuccess
# Le Processus Utilisateur externe / n'affiche Pas de sortie de CE dépassé S'est Qui. Par exemple, si Vous AVEZ le Processus Utilisateur externe / how are exchange rates Raccourci de l'ONU, et il echoue, l'intérieur / admin Processus rien actuellement n'affichera visible verser pertains survenu intérêt qu'un probleme. Parce Que C'Est le Processus Utilisateur externe / communicate NE Pas encore de retour à l'intérieur / Processus admin.
# 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.
# Quand l'ONU ous Utilisateur standard de l'administrateur Limitée informations d'Approvisionnements de Dans la boîte de dialogue Executer de Québec en important, Vous pouvez éprouver l'ennui AVEC les permissions du fichier extrait. Par exemple, si l'ONU Windows 2000 standard info administrateur Utilisateur fournit de Dans la boîte de dialogue Executer de Québec en important, et l'installateur fichier extrait NSIS des Nations Unies. Exe, essayez IUP d'appeler l'ACDE. Exe par l'ONU Exec may échouer. s'agit d'or prohibition Problème de l'ONU, Vous souhaitez utiliser »le [[AccessControl_plug-en | 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]].


=== === Testicules Environnements
===Tested Environments===


Ce plugin, un Été Testé DANS les environnements suivants:
This plugin has been tested under the following environments:


* Windows 7 - UAC Le - Administrateur
* Windows 7 - UAC On - Administrator
* Windows Vista - UAC Le - Administrateur
* Windows Vista - UAC On - Administrator
* Windows Vista - UAC Off - Administrateur
* Windows Vista - UAC Off - Administrator
* Windows Vista - UAC Le - Standard User - Utilisateur de l'info administrateur des Approvisionnements de Dans la boîte de dialogue UAC de
* Windows Vista - UAC On - Standard User - User supplies administrator info into the UAC dialog
* Windows Vista - UAC Le - pas fournit d'informations NE d'administrateur de Dans la boîte de dialogue UAC de - Standard Utilisateur
* Windows Vista - UAC On - Standard User - User does not supply administrator info into the UAC dialog
* Windows Vista - UAC Off - Standard User - Utilisateur de l'info administrateur d'Approvisionnements de Dans la boîte de dialogue Executer de Québec en important
* Windows Vista - UAC Off - Standard User - User supplies administrator info into the Run As dialog
* Windows Vista - UAC Off - pas fournit d'informations NE d'administrateur de Dans la boîte de dialogue Executer de Québec en important - Standard Utilisateur
* Windows Vista - UAC Off - Standard User - User does not supply administrator info into the Run As dialog
* Windows XP - Administrateur
* Windows XP - Administrator
* Windows XP - Limited Utilisateur - info Utilisateur de l'administrateur d'Approvisionnements de Dans la boîte de dialogue Executer de Québec en important
* Windows XP - Limited User - User supplies administrator info into the Run As dialog
* Windows XP - Limited Utilisateur - pas fournit d'informations NE d'administrateur de Dans la boîte de dialogue Executer de Québec en important
* Windows XP - Limited User - User does not supply administrator info into the Run As dialog
Windows 2000 * - Administrateur
* Windows 2000 - Administrator
* Windows 2000 - User Standard - info Utilisateur de l'administrateur d'Approvisionnements de Dans la boîte de dialogue Executer de Québec en important
* Windows 2000 - Standard User - User supplies administrator info into the Run As dialog
* Windows 2000 - Standard Utilisateur - pas fournit d'informations NE d'administrateur de Dans la boîte de dialogue Executer de Québec en important
* Windows 2000 - Standard User - User does not supply administrator info into the Run As dialog
* Windows testicules 95 & 98 Été Ont débuts au rappel de fabrique et UNO esperons du travail (n ° d'ici élévation verser des raisins évidentes)
* Windows 95 & 98 were tested in early builds and hopefully still work (No elevation here for obvious reasons)


Windows ME et NT4 fonctionner n'ont Pas Été Testees, devrait MAIS. (Si Vous AVEZ Testé sur l'ONU de la SCÉ OS'es, s'il vous plaît rendre Compte des Résultats ICI OU sur le forum)
Windows ME & NT4 are untested, but should work. (If you have tested on one of these OS'es, please report results here or on the forum)

Revision as of 15:30, 25 October 2010

Author: Anders (talk, contrib)


Download & Info

This plug-in attempts to work around UAC installation problems on Vista/7. 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 an admin level installer launch another process at a user level. Or you can have an admin level installer create shortcuts at a user level.

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).

Current branch: v0.2.2c

Old branch: v0.0.11d

NOTE: All code on this page applies to the older version, the syntax has changed slightly for 0.2 and you should use the macros in uac.nsh

Basic installation

To install the UAC plugin in your NSIS setup, you just need to copy two files from the above ZIP:

  • For ANSI installers, copy UAC.nsh into your Include directory (e.g. C:\Program Files\NSIS\Include) and UAC.dll from Release/A into your Plugins directory (e.g. C:\Program Files\NSIS\Plugins).
  • For Unicode installers, copy UAC.nsh into your Include directory (e.g. C:\Program Files\NSIS\Unicode\Include) and UAC.dll from Release/U into your Plugins directory (e.g. C:\Program Files\NSIS\Unicode\Plugins).

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 has user privileges (as specified by RequestExecutionLevel user). Immediately, the NSIS installer calls its .onInit code. (Note, no window is visible yet at this point). The UAC plugin makes a second 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 with admin privileges. At 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 will 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.

Examples

NOTE: Syntax has changed in 0.2 alphas, everything on this page uses the old syntax

Many examples are found in the .zip file above. If you want a better idea of what this plugin can do, study those examples. A brief overview of two simple examples are given here:

Creating a user shortcut

UAC_RealWorldExample.nsi does:

Function CreateShortcuts
  CreateShortcut "$Desktop\${APPNAME}.lnk" "$Windir\Notepad.exe"
FunctionEnd
 
Section "Desktop Shortcut"
  GetFunctionAddress $0 CreateShortcuts
  UAC::ExecCodeSegment $0
SectionEnd

In this example, we would want to run the CreateShortcuts function with user privileges, so it can create a user-level shortcut. So first, define the function. Then use GetFunctionAddress to get the address of that function. Then, call UAC::ExecCodeSegment to ask the outer/user process to run that function. Since the function will be run at a user level, it will create a shortcut for the user instead of for the administrator.

Launching an application with user privileges

; !insertmacro UAC_AsUser_ExecShell <Command> <File> <Parameters> <WorkingDir> <ShowWindow>
!insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\${APPFILE}' '-firstrun' '$INSTDIR' ''

Where $INSTDIR\${APPFILE} is the path to the file you want to launch.

If you use the MUI skin and have the installer launch the app for you, you will need to do a little more work.

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION ExecAppFile
 
Function ExecAppFile    
    !insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\${APPFILE}' '-firstrun' '$INSTDIR' ''
FunctionEnd

Keep in mind that you still have to define MUI_FINISHPAGE_RUN (as empty) otherwise MUI won't provide the option at all.

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. Remember to run clean it up with UAC::Unload before your uninstaller exits. Great places to clean it up are un.OnUnInstFailed and un.OnUnInstSuccess
  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.

Tested Environments

This plugin has been tested under the following environments:

  • Windows 7 - UAC On - Administrator
  • 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 95 & 98 were tested in early builds and hopefully still work (No elevation here for obvious reasons)

Windows ME & NT4 are untested, but should work. (If you have tested on one of these OS'es, please report results here or on the forum)