| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 |
<meta name="color-scheme" content="light dark"> |
| 7 |
<title>Multi-User Header File (MultiUser.nsh)</title> |
| 8 |
<style type="text/css"> |
| 9 |
:root { color-scheme: light dark; } |
| 10 |
html, body { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; color: #050505; background-color: #fefefe; } |
| 11 |
html { font-size: 0.9em; } |
| 12 |
body { font-size: 1em; font-size: 1rem; } |
| 13 |
pre, code { font-family: Courier New, Courier, monospace,serif; font-size: 100%; } |
| 14 |
pre, pre code {background-color: #f6f6f6; } |
| 15 |
tr:nth-child(odd) { background-color: #fafafa; } |
| 16 |
table, tr, td { border: 1px solid #dddddd; border-collapse: collapse; } |
| 17 |
td { padding: 0.3em; vertical-align: top; } |
| 18 |
|
| 19 |
@media (prefers-color-scheme: dark) { |
| 20 |
html, body { color: #eeeeee; background-color: #161616; } |
| 21 |
a, a:link, a:visited, a:active { color: #79b; } a:hover { color: #3ad; } |
| 22 |
pre, pre code {background-color: #202020; } |
| 23 |
table, tr, td { border-color: #202020; } |
| 24 |
tr:nth-child(odd) { background-color: #181818; } |
| 25 |
} |
| 26 |
</style> |
| 27 |
</head> |
| 28 |
<body> |
| 29 |
<h1>Multi-User Header File (MultiUser.nsh)</h1> |
| 30 |
<p><i>Installer configuration for multi-user Windows environments</i></p> |
| 31 |
<h2>Table of Contents</h2> |
| 32 |
<ul> |
| 33 |
<li><a href="#introduction">Introduction</a></li> |
| 34 |
<li><a href="#executionlevel">Initialization and Execution Level</a> |
| 35 |
<li><a href="#installationmode">Installation Mode</a> |
| 36 |
<li><a href="#examples">Example</a> |
| 37 |
</ul> |
| 38 |
<h2><a name="introduction"></a>Introduction</h2> |
| 39 |
<p> |
| 40 |
Modern Windows versions support multiple users accounts on a single computer, each |
| 41 |
with different privileges. For security reasons, the privileges of applications |
| 42 |
can also be limited. For an installer, the <i>execution level</i> and <i>installation |
| 43 |
mode</i> are important. The execution level determines the privileges of the |
| 44 |
installer application. For example, to install hardware drivers, administrator privileges |
| 45 |
are required. Applications can also be installed for a single user or for all users |
| 46 |
on a computer, which is determined by the installation mode. Installation for all |
| 47 |
users requires a higher execution level as compared with a single user setup. The |
| 48 |
MultiUser.nsh header files provides the features to automatically handle all these |
| 49 |
aspects related to user accounts and installer privileges.</p> |
| 50 |
<p> |
| 51 |
Note that all settings need to be set before including the MultiUser.nsh header |
| 52 |
file.</p> |
| 53 |
<h2>Initialization and <a name="executionlevel"></a>Execution Level </h2> |
| 54 |
<p> |
| 55 |
Before the MultiUser.nsh file is included, the MULTIUSER_EXECUTIONLEVEL define should |
| 56 |
be set to one of the following values depending on the execution level that is required:</p> |
| 57 |
<table> |
| 58 |
<tr> |
| 59 |
<td> |
| 60 |
<b>Value </b> |
| 61 |
</td> |
| 62 |
<td> |
| 63 |
<b>Description</b> |
| 64 |
</td> |
| 65 |
<td> |
| 66 |
<b>Typical application</b> |
| 67 |
</td> |
| 68 |
</tr> |
| 69 |
<tr> |
| 70 |
<td> |
| 71 |
Admin |
| 72 |
</td> |
| 73 |
<td> |
| 74 |
Administrator privileges are required |
| 75 |
</td> |
| 76 |
<td> |
| 77 |
Access data of all users accounts |
| 78 |
</td> |
| 79 |
</tr> |
| 80 |
<tr> |
| 81 |
<td> |
| 82 |
Power |
| 83 |
</td> |
| 84 |
<td> |
| 85 |
Power User privileges are required<br> |
| 86 |
(Power Users no longer exist in Windows Vista. For Vista this is equivalent to Admin) |
| 87 |
</td> |
| 88 |
<td> |
| 89 |
Installation for all users (writing to "Program Files" or HKLM registry |
| 90 |
keys), driver installation |
| 91 |
</td> |
| 92 |
</tr> |
| 93 |
<tr> |
| 94 |
<td> |
| 95 |
Highest |
| 96 |
</td> |
| 97 |
<td> |
| 98 |
Request the highest possible execution level for the current user |
| 99 |
</td> |
| 100 |
<td> |
| 101 |
Mixed-mode installer that can both be installed per-machine or per-user |
| 102 |
</td> |
| 103 |
</tr> |
| 104 |
<tr> |
| 105 |
<td> |
| 106 |
Standard |
| 107 |
</td> |
| 108 |
<td> |
| 109 |
No special rights required |
| 110 |
</td> |
| 111 |
<td> |
| 112 |
Installation for current user only |
| 113 |
</td> |
| 114 |
</tr> |
| 115 |
</table> |
| 116 |
<p> |
| 117 |
Insert the MULTIUSER_INIT and MULTIUSER_UNINT macros in the .onInit and un.onInit |
| 118 |
function to verify these privileges. If no uninstaller is created in the script, |
| 119 |
define MULTIUSER_NOUNINSTALL.</p> |
| 120 |
<pre><code>!define MULTIUSER_EXECUTIONLEVEL Highest |
| 121 |
;!define MULTIUSER_NOUNINSTALL ;Uncomment if no uninstaller is created |
| 122 |
!include MultiUser.nsh |
| 123 |
|
| 124 |
... |
| 125 |
|
| 126 |
Function .onInit |
| 127 |
!insertmacro MULTIUSER_INIT |
| 128 |
FunctionEnd |
| 129 |
|
| 130 |
Function un.onInit |
| 131 |
!insertmacro MULTIUSER_UNINIT |
| 132 |
FunctionEnd</code></pre> |
| 133 |
<p> |
| 134 |
Whether the required privileges can be obtained depends on the user that starts |
| 135 |
the installer:</p> |
| 136 |
<ul> |
| 137 |
<li>Windows NT 4/2000/XP/2003 give the installer the same privileges as the user itself. |
| 138 |
If the privileges of the user are not sufficient (e.g. Admin level is required is |
| 139 |
set but the user has no administrator rights), the macros will display an error |
| 140 |
message and quit the installer. If is however possible to manually run the installer |
| 141 |
with an administrator account.</li> |
| 142 |
<li>Windows Vista restricts the privileges of all applications by default. Depending |
| 143 |
on requested execution level, MultiUser.nsh will set the RequestExecutionLevel flag |
| 144 |
to request privileges. The user will be asked for confirmation and (if necessary) |
| 145 |
for an administrator password.</li> |
| 146 |
<li>Windows 95/98/98 do not set any restrictions on users or applications. Administrator |
| 147 |
rights are always available.</li> |
| 148 |
</ul> |
| 149 |
<p> |
| 150 |
It is recommended to insert these initialization macros before macros that require |
| 151 |
user intervention. For example, it does not make sense to ask a user for an installer |
| 152 |
language if the installer will quit afterwards because the user account does not |
| 153 |
have the required privileges. After the macros are inserted, the variable $MultiUser.Privileges |
| 154 |
will contain the current execution level (Admin, Power, User or Guest).</p> |
| 155 |
<p> |
| 156 |
The following additional settings are available to customize the initialization:</p> |
| 157 |
<table> |
| 158 |
<tr> |
| 159 |
<td><b>Setting</b></td> |
| 160 |
<td><b>Description</b></td> |
| 161 |
</tr> |
| 162 |
<tr> |
| 163 |
<td> |
| 164 |
MULTIUSER_INIT_TEXT_ADMINREQUIRED |
| 165 |
</td> |
| 166 |
<td> |
| 167 |
Error message to be displayed when administrator rights are required but not available. |
| 168 |
</td> |
| 169 |
</tr> |
| 170 |
<tr> |
| 171 |
<td> |
| 172 |
MULTIUSER_INIT_TEXT_POWERREQUIRED |
| 173 |
</td> |
| 174 |
<td> |
| 175 |
Error message to be displayed when Power User rights are required but not available. |
| 176 |
</td> |
| 177 |
</tr> |
| 178 |
<tr> |
| 179 |
<td> |
| 180 |
MULTIUSER_INIT_TEXT_ALLUSERSNOTPOSSIBLE |
| 181 |
</td> |
| 182 |
<td> |
| 183 |
Error message to be displayed when administrator or Power User rights are required |
| 184 |
because of an installation mode setting on the command line (see below) but are |
| 185 |
not available. |
| 186 |
</td> |
| 187 |
</tr> |
| 188 |
<tr> |
| 189 |
<td> |
| 190 |
MULTIUSER_USE_PROGRAMFILES64 |
| 191 |
</td> |
| 192 |
<td> |
| 193 |
Use $PROGRAMFILES64 instead of $PROGRAMFILES as the default all users directory. |
| 194 |
</td> |
| 195 |
</tr> |
| 196 |
<tr> |
| 197 |
<td> |
| 198 |
MULTIUSER_INIT_FUNCTIONQUIT<br> |
| 199 |
MULTIUSER_INIT_UNFUNCTIONQUIT |
| 200 |
</td> |
| 201 |
<td> |
| 202 |
A custom function to be called when the installer is closed due to insufficient |
| 203 |
privileges. |
| 204 |
</td> |
| 205 |
</tr> |
| 206 |
</table> |
| 207 |
<h2><a name="installationmode"></a>Installation Mode</h2> |
| 208 |
<p> |
| 209 |
As mentioned before, applications can both be installed for a single users or for |
| 210 |
all users on a computer. Applications for all users are typically installed in the |
| 211 |
Program Files folder and appear in the Start Menu of every user. On the contrary, |
| 212 |
applications for a single user are usually installed in the local Application Data |
| 213 |
folder and only a appear in the Start Menu of the user who installed the application.</p> |
| 214 |
<p> |
| 215 |
By default, MultiUser.nsh will set the installation mode for a per-machine installation |
| 216 |
if Administrator or Power User rights are available (this is always the case if |
| 217 |
the execution level is set to Admin or Power, if Highest is set it depends on the |
| 218 |
user account). For the Standard execution level the installation will always be |
| 219 |
for a single user. On Windows 95/98/Me installation for a single user is not possible, a per-machine installation will be performed.</p> |
| 220 |
<p> |
| 221 |
The following settings are available to change the default installation mode: |
| 222 |
<table> |
| 223 |
<tr> |
| 224 |
<td><b>Setting</b></td> |
| 225 |
<td><b>Description</b></td> |
| 226 |
</tr> |
| 227 |
<tr> |
| 228 |
<td> |
| 229 |
MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER |
| 230 |
</td> |
| 231 |
<td> |
| 232 |
Set default to a per-user installation, even if the rights for a per-machine installation |
| 233 |
are available. |
| 234 |
</td> |
| 235 |
</tr> |
| 236 |
<tr> |
| 237 |
<td> |
| 238 |
MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME |
| 239 |
</td> |
| 240 |
<td> |
| 241 |
Non-empty registry key that is created during the installation in either HKCU or |
| 242 |
HKLM. The default installation mode will automatically be set to the previously |
| 243 |
selected mode depending on the location of the key. |
| 244 |
</td> |
| 245 |
</tr> |
| 246 |
</table> |
| 247 |
<p> |
| 248 |
After initialization, the variable $MultiUser.InstallMode will contain the current |
| 249 |
installation mode (AllUsers or CurrentUser). |
| 250 |
</p> |
| 251 |
<h3>Mixed-Mode Installation</h3> |
| 252 |
<p> |
| 253 |
For the Admin and Power levels, both a per-machine as well as a per-user installation |
| 254 |
is possible. If the Highest level is set and the user is an Administrator or Power |
| 255 |
User, both options are also available.</p> |
| 256 |
<p> |
| 257 |
Usually it's a good thing to give the user to choice between these options. For |
| 258 |
users of the Modern UI version 2, a page is provided that asks the user for the |
| 259 |
installation mode. To use this page, define MULTIUSER_MUI before including MultiUser.nsh. |
| 260 |
Then, the MULTIUSER_PAGE_INSTALLMODE macro can be used just like a normal Modern |
| 261 |
UI page (this page will automatically be skipped when running Windows 95/98/Me):</p> |
| 262 |
<pre><code>!define MULTIUSER_EXECUTIONLEVEL Highest |
| 263 |
<b>!define MULTIUSER_MUI</b> |
| 264 |
!define MULTIUSER_INSTALLMODE_COMMANDLINE |
| 265 |
!include MultiUser.nsh |
| 266 |
!include MUI2.nsh |
| 267 |
|
| 268 |
<b>!insertmacro MULTIUSER_PAGE_INSTALLMODE</b> |
| 269 |
!insertmacro MUI_PAGE_DIRECTORY |
| 270 |
!insertmacro MUI_PAGE_INSTFILES |
| 271 |
|
| 272 |
!insertmacro MUI_LANGUAGE English |
| 273 |
|
| 274 |
... |
| 275 |
|
| 276 |
Function .onInit |
| 277 |
!insertmacro MULTIUSER_INIT |
| 278 |
FunctionEnd |
| 279 |
|
| 280 |
Function un.onInit |
| 281 |
!insertmacro MULTIUSER_UNINIT |
| 282 |
FunctionEnd</code></pre> |
| 283 |
<p> |
| 284 |
The MULTIUSER_INSTALLMODE_COMMANDLINE setting that also appears in this example |
| 285 |
enables the installation mode to be set using the /AllUsers or /CurrentUser command |
| 286 |
line parameters. This is especially useful for silent setup.</p> |
| 287 |
<p> |
| 288 |
The following settings can be used to customize the texts on the page (in addition |
| 289 |
to the general Modern UI page settings):</p> |
| 290 |
<table> |
| 291 |
<tr> |
| 292 |
<td><b>Setting</b></td> |
| 293 |
<td><b>Description</b></td> |
| 294 |
</tr> |
| 295 |
<tr> |
| 296 |
<td>MULTIUSER_INSTALLMODEPAGE_TEXT_TOP</td> |
| 297 |
<td>Text to display on the top of the page.</td> |
| 298 |
</tr> |
| 299 |
<tr> |
| 300 |
<td>MULTIUSER_INSTALLMODEPAGE_TEXT_ALLUSERS</td> |
| 301 |
<td>Text to display on the radio button for a per-machine installation.</td> |
| 302 |
</tr> |
| 303 |
<tr> |
| 304 |
<td>MULTIUSER_INSTALLMODEPAGE_TEXT_CURRENTUSER</td> |
| 305 |
<td>Text to display on the radio button for a per-user installation.</td> |
| 306 |
</tr> |
| 307 |
<tr> |
| 308 |
<td>MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME</td> |
| 309 |
<td>Append the username to the per-user radio button.</td> |
| 310 |
</tr> |
| 311 |
</table> |
| 312 |
<h3>Installation Mode Initialization</h3> |
| 313 |
<p> |
| 314 |
The SetShellVarContext flag (which determines the folders for e.g. shortcuts, like |
| 315 |
$DESKTOP) is automatically set depending on the installation mode. In addition, |
| 316 |
the following settings can be used to perform additional actions when the installation |
| 317 |
mode is initialized:</p> |
| 318 |
<table> |
| 319 |
<tr> |
| 320 |
<td><b>Setting</b></td> |
| 321 |
<td><b>Description</b></td> |
| 322 |
</tr> |
| 323 |
<tr> |
| 324 |
<td>MULTIUSER_INSTALLMODE_INSTDIR</td> |
| 325 |
<td> |
| 326 |
Name of the folder in which to install the application, without a path. This folder |
| 327 |
will be located in Program Files for a per-machine installation and in the local |
| 328 |
Application Data folder for a per-user installation (if supported). |
| 329 |
</td> |
| 330 |
</tr> |
| 331 |
<tr> |
| 332 |
<td>MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME</td> |
| 333 |
<td> |
| 334 |
Registry key from which to obtain a previously stored installation folder. It will |
| 335 |
be retrieved from HKCU for per-user and HKLM for per-machine. |
| 336 |
</td> |
| 337 |
</tr> |
| 338 |
<tr> |
| 339 |
<td> |
| 340 |
MULTIUSER_INSTALLMODE_FUNCTION<br> |
| 341 |
MULTIUSER_INSTALLMODE_UNFUNCTION |
| 342 |
</td> |
| 343 |
<td> |
| 344 |
A custom function to be called during the initialization of the installation mode |
| 345 |
to set additional installer settings that depend on the mode |
| 346 |
</td> |
| 347 |
</table> |
| 348 |
<p> |
| 349 |
To set the installation mode manually, call one of these four functions:</p> |
| 350 |
<table> |
| 351 |
<tr> |
| 352 |
<td> |
| 353 |
<b>Function name</b> |
| 354 |
</td> |
| 355 |
<td> |
| 356 |
<b>Installation mode</b> |
| 357 |
</td> |
| 358 |
</tr> |
| 359 |
<tr> |
| 360 |
<td> |
| 361 |
MultiUser.InstallMode.AllUsers |
| 362 |
</td> |
| 363 |
<td> |
| 364 |
Installer: Per-machine installation |
| 365 |
</td> |
| 366 |
</tr> |
| 367 |
<tr> |
| 368 |
<td> |
| 369 |
MultiUser.InstallMode.CurrentUser |
| 370 |
<td> |
| 371 |
Installer: Per-user installation |
| 372 |
</td> |
| 373 |
</tr> |
| 374 |
<tr> |
| 375 |
<td> |
| 376 |
un.MultiUser.InstallMode.AllUsers<td> |
| 377 |
Uninstaller: Per-machine installation |
| 378 |
</td> |
| 379 |
</tr> |
| 380 |
<tr> |
| 381 |
<td> |
| 382 |
un.MultiUser.InstallMode.CurrentUser<td> |
| 383 |
Uninstaller: Per-user installation |
| 384 |
</td> |
| 385 |
</tr> |
| 386 |
</table> |
| 387 |
|
| 388 |
<h2><a name="examples"></a>Example</h2> |
| 389 |
Basic: <a href="../../Examples/MultiUser.nsi">MultiUser.nsi</a><br /> |
| 390 |
</body> |
| 391 |
</html> |