Windows Vista Uac Dev Reqs
Windows Vista Uac Dev Reqs
Abstract
This white paper is intended to assist application developers with designing Windows
Vista capable applications that are User Account Control compliant. Detailed steps about
the design process are included, along with code samples, requirements, and best
practices. This paper also details the technical updates and changes to the user
experience in Windows Vista.
This is a preliminary document and may be changed substantially prior to final
commercial release of the software described herein.
The information contained in this document represents the current view of Microsoft
Corporation on the issues discussed as of the date of publication. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any
information presented after the date of publication.
This White Paper is for informational purposes only. MICROSOFT MAKES NO
WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN
THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without
limiting the rights under copyright, no part of this document may be reproduced, stored in
or introduced into a retrieval system, or transmitted in any form or by any means
(electronic, mechanical, photocopying, recording, or otherwise), or for any purpose,
without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other
intellectual property rights covering subject matter in this document. Except as expressly
provided in any written license agreement from Microsoft, the furnishing of this document
does not give you any license to these patents, trademarks, copyrights, or other
intellectual property.
Unless otherwise noted, the example companies, organizations, products, domain
names, e-mail addresses, logos, people, places and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, email
address, logo, person, place or event is intended or should be inferred.
© 2006 Microsoft Corporation. All rights reserved.
Microsoft, ActiveX, ClickOnce, IntelliMirror, Microsoft .NET, Visual Studio, Windows
Installer, Windows NT, Windows Vista, and Windows XP are either registered trademarks
or trademarks of Microsoft Corporation in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks
of their respective owners.
Contents
Windows Vista Application Development Requirements for User Account Control
Compatibility................................................................................................................... 7
Why User Account Control?............................................................................................ 7
Windows Vista Updates.............................................................................................. 9
UAC is Enabled by Default......................................................................................9
All Subsequent User Accounts are Created as Standard Users..............................9
Elevation Prompts are Displayed on the Secure Desktop by Default.......................9
Elevation Prompts for Background Applications are Minimized to the Taskbar......10
Elevations are blocked in the User's Logon Path...................................................10
Built-in Administrator Account is Disabled by Default on New Installations............10
User Account Control and Remote Scenarios........................................................11
New Default Access Control List (ACL) Settings....................................................11
New UAC Security Settings and Security Setting Name Changes.........................13
How UAC Works........................................................................................................... 13
New Technologies for Windows Vista........................................................................13
ActiveX Installer Service........................................................................................ 13
Installer Detection.................................................................................................. 14
Patching Applications in a UAC Environment.........................................................15
Security Center Integration....................................................................................15
User Interface Privilege Isolation...........................................................................15
Virtualization.......................................................................................................... 17
Access Token Changes.......................................................................................... 21
UAC Architecture....................................................................................................... 23
Standard User Launch Path...................................................................................25
Elevated Launch Path............................................................................................ 25
Will UAC Affect your Application?.................................................................................25
Why Do I Need to Remove My Application’s Administrative Dependencies?............26
Reducing Your Application's Total Cost of Ownership............................................26
Secure by Default.................................................................................................. 26
How Do I Determine If My Application Has Administrative Dependencies?...............28
What Are the Requirements If I Have a Legitimate Administrator Application?.........29
Designing Applications for Windows Vista....................................................................29
Step One: Test Your Application for Application Compatibility...................................30
Step Two: Classify Your Application as a Standard User, Administrator, or Mixed User
Application............................................................................................................. 31
Questions to Help Classify Your Application..........................................................31
Analyzing the Answers to Classify Your Application...............................................33
Verify the Application or Control Panel Works with UAC:.......................................33
Step Three: Redesign Your Application's Functionality for UAC Compatibility..........33
Windows Vista Application Run-time Requirements..............................................33
Step Four: Redesign Your Application's User Interface for UAC Compatibility..........41
Impact of UAC on the Windows User Experience..................................................41
Goals of the UAC User Experience........................................................................41
Elevation Prompt.................................................................................................... 42
User Experience Process Flow..............................................................................44
Elevation Entry Points............................................................................................ 45
User Interface Implementation...............................................................................49
When to Add the Shield Icon to Your Application's User Interface.........................52
Key Decisions for Designing Administrator-Only Applications................................55
Step Five: Redesign Your Application's Installer........................................................58
Step Six: Create and Embed an Application Manifest with Your Application.............60
Application Manifest Schema.................................................................................60
How to Create an Embedded Manifest with Microsoft Visual Studio®...................65
Building Application Manifests within C/C++ Code with Visual Studio® 2005 for
Windows Vista Only Applications........................................................................66
Building and Embedding a Manifest with Microsoft Visual Studio® 2005 for
Windows XP and Windows Vista Applications....................................................67
Step Seven: Test Your Application.............................................................................68
Step Eight: Authenticode Sign Your Application........................................................69
Example Signing Procedure..................................................................................69
Step Nine: Participate in the Windows Vista Logo Program......................................71
Deploying and Patching Applications for Standard Users.............................................71
Deploying to a Single Computer................................................................................72
Deploying to all users in a Domain............................................................................72
Patching Applications as a Standard User with Windows Installer 4.0......................72
Windows Installer 4.0 Standard User Uninstall Behavior.......................................73
Troubleshooting Common Issues.................................................................................73
ActiveX Installation Issues.........................................................................................73
Resolution.............................................................................................................. 73
ActiveX Documents Do Not Install.............................................................................74
Resolution.............................................................................................................. 74
Application, Framework, or Add-in Required.............................................................74
Resolution.............................................................................................................. 74
Administrative Permission is Required for Installation/Patching................................74
Resolution.............................................................................................................. 75
Per-User Application Settings Locations...................................................................75
Application Defaults to Saving in a Protected Directory............................................76
Resolution.............................................................................................................. 77
References................................................................................................................... 77
Virtualization Reference............................................................................................77
File virtualization.................................................................................................... 77
Registry Virtualization:........................................................................................... 77
Applicability............................................................................................................ 77
UAC Security Settings Reference.............................................................................78
Configuring UAC Security Settings........................................................................78
UAC Security Settings........................................................................................... 79
Task Scheduler Code Sample...................................................................................86
7
Note
There is one exception to the preceding statement: Guests log onto the computer
with fewer user rights and privileges than standard users.
When an administrator attempts to perform an administrative task, such as installing an
application, UAC prompts the user to approve the action. When the user approves the
action, the task is launched with the administrator's full administrator access token. This
is the default administrator prompt behavior, and it is configurable in the local Security
Policy Manager snap-in (secpol.msc) and with Group Policy (gpedit.msc).
9
Note
An administrator account on a Windows Vista computer with UAC enabled is also
called an administrator account in Admin Approval Mode. Admin Approval Mode
identifies the default user experience for administrators.
Each administrative elevation is also process specific, which prevents other processes
from using the access token without prompting the user for approval. As a result,
administrator users have more granular control on what applications install while greatly
impacting malicious software that expects the logged on user to be running with a full
administrator access token.
Standard users also have the opportunity to elevate in flow and perform administrative
tasks by using the UAC infrastructure. When a standard user attempts to perform an
administrative task, UAC prompts the user to enter valid credentials for an administrator
account. This is the default standard user prompt behavior, and it is configurable in the
local Security Policy Manager snap-in (secpol.msc) and with Group Policy (gpedit.msc).
Non-Domain Joined
When there is at least one enabled local administrator account, safe mode will not allow
logon with the disabled built-in administrator account. Instead, any local administrator
11
account can be used to logon. If the last local administrator account is inadvertently
demoted, disabled, or deleted then safe mode will allow the disabled built-in administrator
account to logon for disaster recovery.
Domain Joined
The disabled built-in administrator account in all cases cannot logon in safe mode. A user
account that is a member of the Domain Admins group can log on to the computer to
create a local administrator if none exists.
Note
If the domain administrative account had never logged on before, then the
computer must be started in Safe Mode with Networking since the credentials will
not have been cached.
Note
Once the machine is disjoined, it will revert back to the non-domain joined
behavior depicted previously.
BUILTIN\Users Read
Special access: FILE_APPEND_DATA
Special access: FILE_WRITE_DATA
Everyone Read
The following table details the new Windows Vista data drive ACL settings for data drives
created with format.exe.
The following table details the new Windows Vista operating system root (%systemroot%)
ACL settings.
Installer Detection
Installation programs are applications designed to deploy software, and most write to
system directories and registry keys. These protected system locations are typically
writeable only by administrator users; this means that standard users do not have
sufficient access to install programs. Windows Vista heuristically detects installation
programs and requests administrator credentials or approval from the administrator user
in order to run with access privileges. Windows Vista also heuristically detects updater
and un-installation programs. Note that a design goal of UAC is to prevent installations
from being executed without the user's knowledge and consent since they write to
protected areas of the file system and registry.
Important
When developing new installation programs, much like developing programs for
Windows Vista, be sure to embed an application manifest with an appropriate
requestedExecutionLevel element (see the Step Six: Create and Embed an
Application Manifest with Your Application section). When the
requestedExecutionLevel is present in the embedded application manifest, it
overrides Installer Detection.
Installer Detection only applies to:
1. 32 bit executables
2. Applications without a requestedExecutionLevel
3. Interactive processes running as a Standard User with LUA enabled
Before a 32 bit process is created, the following attributes are checked to determine
whether it is an installer:
Filename includes keywords like "install," "setup," "update," etc.
Keywords in the following Versioning Resource fields: Vendor, Company Name,
Product Name, File Description, Original Filename, Internal Name, and Export Name.
Keywords in the side-by-side manifest embedded in the executable.
Keywords in specific StringTable entries linked in the executable.
Key attributes in the RC data linked in the executable.
Targeted sequences of bytes within the executable.
Note
The keywords and sequences of bytes were derived from common
characteristics observed from various installer technologies.
Ensure that you thoroughly review the entirety of this document, including the Step Six:
Create and Embed an Application Manifest with Your Application section.
15
Note
The User Account Control: Detect application installations and prompt for
elevation setting must be enabled for installer detection to detect installation
programs. This setting is enabled by default and can be configured with the
Security Policy Manager snap-in (secpol.msc) or with Group Policy (gpedit.msc).
General information and an overview of the Microsoft Windows Installer can be found at
MSDN (http://go.microsoft.com/fwlink/?LinkId=30197).
assigned in the process’s security access token. The desktop integrity level is set by the
security subsystem when the process is created and does not change. Hence, the user
interface privilege level also is set by the User subsystem when the process is created
and does not change.
All applications run by a standard user have the same user interface privilege level. As a
standard user, applications are run at a single privilege level. UIPI does not interfere or
change the behavior of window messaging between applications at the same privilege
level. UIPI comes into effect for a user who is a member of the administrators group and
may be running applications as a standard user (sometimes referred to as a process with
a filtered access token) and also processes running with a full administrator access token
on the same desktop. UIPI prevents lower privilege processes from accessing higher
privilege processes by blocking the following behavior.
A lower privilege process cannot:
Perform a window handle validation of higher process privilege.
SendMessage or PostMessage to higher privilege application windows. These
application programming interfaces (APIs) return success but silently drop the
window message.
Use thread hooks to attach to a higher privilege process.
Use Journal hooks to monitor a higher privilege process.
Perform dynamic link-library (DLL) injection to a higher privilege process.
With UIPI enabled, the following shared USER resources are still shared between
processes at different privilege levels:
Desktop window, which actually owns the screen surface
Desktop heap read-only shared memory
Global atom table
Clipboard
Painting to the screen is another action that is not blocked by UIPI. Painting to the screen
refers to the process of using the Paint method to display content on an external output—
a monitor, for example. The USER/graphics device interface (GDI) model does not allow
control over painting surfaces; therefore, it is possible for a lower privilege application to
paint over the surface region of a higher privilege application window.
Note
Because the Windows Shell (Explorer) is running as a standard user process,
any other process running as standard user can still send it keystrokes. This is
the primary reason why an administrator account in Admin Approval Mode is
prompted for elevation consent when it initiates an administrative action, such as
double-clicking on a Setup.exe or clicking on an elevation Shield icon.
17
Virtualization
Important
Virtualization is implemented to improve application compatibility problems for
applications running as a standard user on Windows Vista. Developers must not
rely on virtualization being present in subsequent versions of Windows.
Prior to Windows Vista, many applications were typically run by administrators. As a
result, applications could freely read and write system files and registry keys. If these
applications were run by a standard user, they would fail due to insufficient access.
Windows Vista improves application compatibility for these users by redirecting writes
(and subsequent file or registry operations) to a per-user location within the user’s profile.
For example, if an application attempts to write to C:\Program Files\Contoso\Settings.ini,
and the user does not have permissions to write to that directory, the write will get
redirected to C:\Users\<user name>\AppData\Local\VirtualStore\Program Files\contoso\
settings.ini. For the registry, if an application attempts to write to
HKEY_LOCAL_MACHINE\Software\Contoso\ it will automatically get redirected to
HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\Software\Contoso or
HKEY_USERS\< User SID >_Classes\VirtualStore\Machine\Software\Contoso.
The following figure details the virtualization process in Windows Vista. In this example,
Denise is an administrator in Admin Approval Mode and Brian is a standard user.
Virtualization is comprised of two components: file virtualization and registry virtualization.
Virtualization process
18
Important
While developing Windows Vista programs, to reduce the complexity of
virtualized files and registry keys, be sure to embed an application manifest with
an appropriate requestedExecutionLevel in order to turn off file and registry
virtualization.
Virtualization is only enabled for:
32 bit interactive processes
Administrator writeable file/folder and registry keys
Virtualization is disabled for:
64 bit processes
Non-interactive processes
Processes that impersonate
Kernel mode callers
Executables that have a requestedExecutionLevel
Virtualization and roaming:
Virtualization files/folder and registry keys do not roam (see roaming profiles)
Associated with global objects that do not roam
File Virtualization
File virtualization addresses the situation where an application relies on the ability to
store a file, such as a configuration file, in a system location typically writeable only by
administrators. Running programs as a standard user in this situation might result in
program failures due to insufficient levels of access.
When an application writes to a system location only writeable by administrators,
Windows then writes all subsequent file operations to a user-specific path under the
Virtual Store directory, which is located at %LOCALAPPDATA%\VirtualStore. Later, when
the application reads back this file, the system will provide the one in the Virtual Store.
Because the Windows security infrastructure processes the virtualization without the
application’s assistance, the application believes it was able to successfully read and
write directly to Program Files. The transparency of file virtualization enables applications
the perception that they are writing and reading from the protected resource, when in fact
they are accessing the virtualized version.
Note
When you enumerate resources in folders and in the registry, Windows Vista will
merge global file/folder and registry keys into a single list. In this merged view,
the global (protected) resource is listed along with the virtualized resource.
19
Important
The virtual copy will always be present to the application first. For example,
config.ini is available in \PF\App\config.ini and %LOCALAPPDATA%\VirtualStore\
config.ini, and the config.ini in the virtual store will always be the one read, even
if \PF\App\config.ini is updated.
The following figure details how global and merged views for virtualized resources are
displayed for different users.
Note
For Syed to discover his virtualized files, he must navigate to the virtual store
with the Compatibility files button on the Explorer toolbar.
However, after Stuart Munson, another sales representative, logs in to the workstation,
he will NOT see the file SalesData.txt in the Program Files\SalesV1\ directory. If different
user uses the computer and writes the \Program files\SalesV1\SalesData.txt file, that
20
write will also virtualize to that user's virtual store. The files Syed updates and saves will
remain independent of the other virtualized files on the system.
Registry Virtualization
Registry virtualization is similar to file virtualization but applies to registry keys under
HKEY_LOCAL_MACHINE\SOFTWARE. This feature permits applications that rely on the
ability to store configuration information in HKEY_LOCAL_MACHINE\SOFTWARE to
continue to when they are run under a standard user account. The keys and data are
redirected to HKEY_CLASSES_ROOT\VirtualStore\SOFTWARE. As in the file
virtualization case, each user has a virtualized copy of any values that an application
stored in HKLM.
Registry Virtualization Details
Can be turned on/off on individual keys in the Software hive
New FLAGS option in reg.exe for key level virtualization control: Allows recursive
enable/disable of virtualization and control of “open access right policy”
ZwQueryKey: Programmatically query the virtualization flags for a key.
Virtualization happens on top of WoW64 redirection
Enabled both in the 64 bit and 32 bit registry views: HKU\{SID}_Classes\VirtualStore\
Machine\Software and HKU\{SID}_Classes\VirtualStore\Machine\Software\
SYSWOW3264
Most legacy 32 bit apps will use the 32 bit view
Virtualization is intended only to assist in application compatibility with existing programs.
Applications designed for Windows Vista should NOT perform writes to sensitive system
areas, nor should they rely on virtualization to provide redress for incorrect application
behavior. When updating existing code to run on Windows Vista, developers should
ensure that, during run-time, applications only store data in per-user locations or in
computer locations within %alluserprofile% (CSIDL_COMMON_APPDATA) that have
access control list (ACL) settings properly set.
Important
Microsoft intends to remove virtualization from future versions of the Windows
operating system as more applications are migrated to Windows Vista. For
example, virtualization is disabled on 64-bit applications.
Virtualization Recommendations
Virtualization is intended only to assist in application compatibility with existing programs.
Applications designed for Windows Vista should NOT perform writes to sensitive system
areas, nor should they rely on virtualization to provide redress for incorrect application
behavior. When updating existing code to run on Windows Vista, developers should
21
ensure that, during run-time, applications only store data in per-user locations or in
computer locations within %alluserprofile% that have access control list (ACL) settings
properly set.
Important
Microsoft intends to remove virtualization from future versions of the Windows
operating system as more applications are migrated to Windows Vista. For
example, virtualization is disabled on 64-bit applications.
Add an application manifest with an appropriate requestedExecutionLevel for your
interactive applications. This will turn virtualization off for the manifested application.
Do not use the registry as an inter-process communication mechanism. Services and
user applications will have different views of the key.
Test your application on Windows Vista: Ensure that processes running as standard
user do not write to global namespaces like %systemroot%.
For filter driver developers: Check your altitude range
(http://go.microsoft.com/fwlink/?LinkId=71503). See File System Filters and fltmc.exe
(http://go.microsoft.com/fwlink/?LinkId=71504). These must be higher than FSFilter
virtualization.
Remember that virtualized resources are per-user copies of global resources.
DOMAIN_ALIAS_RID_PRINT_OPS
DOMAIN_ALIAS_RID_BACKUP_OPS
DOMAIN_ALIAS_RID_RAS_SERVERS
DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
DOMAIN_ALIAS_RID_CRYPTO_OPERATORS
2. The user’s account contains any privileges other than those of a standard user
account. A standard user account contains only the following privileges.
SeChangeNotifyPrivilege
SeShutdownPrivilege
SeUndockPrivilege
SeIncreaseWorkingSetPrivilege
SeTimeZonePrivilege
Note
What privileges the filtered token contain are based on whether the original token
contained any of the restricted RIDS listed above. If any of the restricted RIDs
were in the token, all of the privileges are removed except:
SeChangeNotifyPrivilege
SeShutdownPrivilege
SeUndockPrivilege
SeReserveProcessorPrivilege
SeTimeZonePrivilege
If no restricted RIDs were in the token, only the following privileges are removed:
SeCreateTokenPrivilege
SeTcbPrivilege
SeTakeOwnershipPrivilege
SeBackupPrivilege
SeRestorePrivilege
SeDebugPrivilege
SeImpersonatePrivilege
SeRelabelPrivilege
The first access token, called the filtered access token, has the previous RIDs (if present)
marked as USE_FOR_DENY_ONLY in the access token and the administrative Windows
privileges, not listed previously, removed. The filtered access token will be used by
23
default when the user launches applications. The unmodified full access token, called the
linked access token, is attached to the filtered access token and is used when requests
are made to launch applications with a full administrative access token.
More information on RIDs can be found at MSDN (http://go.microsoft.com/fwlink/?
LinkId=71494).
More information on Windows privileges can be found at MSDN
(http://go.microsoft.com/fwlink/?LinkId=71495).
UAC Architecture
The following diagram represents the process flow for executable launches in Windows
Vista.
24
UAC architecture
The following is a description of the process flow displayed in the UAC architecture
diagram and how UAC is implemented when an executable attempts to launch.
25
Note
If an application works well as standard user on Windows XP, then it will work
well as a standard user on Windows Vista.
Secure by Default
At Microsoft, the tenets of Microsoft's Trustworthy Computing Initiative have been
ingrained into software development. Consequently, improved security has been an
integral part of the Windows Vista development process.
27
Important
Microsoft still recommends that members of the Domain Admins group continue
to maintain two separate user accounts in Windows Vista: a standard user
account and a domain administrator user account. All domain administration
should be done with the domain administrator account. To further enhance
security, consider deploying a smart card (http://go.microsoft.com/fwlink/?
LinkId=71505) solution in domain environments.
The following are Windows Vista design goals for Admin Approval Mode:
Eliminate the need for two separate accounts for users who are members of the
administrators group: This goal is accomplished by running programs only with a
standard user access token unless the user provides approval to use the full
administrative access token.
Protect processes running with a full administrative access token from being
accessed or modified by those processes running as a standard user.
Provide for a seamless transition between administrator and standard user
workspaces.
Currently, most Windows applications must be run as an administrator but do not actually
perform administrative operations. These applications are a byproduct of the Microsoft
Windows® 9x operating systems philosophy: “everyone is an administrator.”
The following are examples of problematic applications:
Applications that unnecessarily write to HKEY_LOCAL_MACHINE (HKLM) or to
system files within the file system.
An ActiveX® installation to facilitate a line-of-business application with a Web
interface.
Applications that unnecessarily request access to resources that require a full
administrative access token.
The next section presents new technologies for Windows Vista that impact ISVs.
installs and runs properly under a standard user account on Windows XP. The application
may perform operations, such as attempting to write to system registry locations, and
make decisions based on the system’s behavior, such as looking for an error response.
Windows Vista may behave differently than earlier versions of the Windows operating
system due to the addition of new application compatibility support. Therefore, it is
recommended that all applications be tested with the new version of the Standard User
Analyzer, which can be downloaded from Microsoft (http://go.microsoft.com/fwlink/?
LinkId=71359).
The Standard User Analyzer will record all administrative operations encountered by an
application, including registry/file system access and elevated API calls. This data is
stored in a log file and is displayed within the tool. The Standard User Analyzer identifies
the following common dependencies, in addition to many others:
Dependency on objects that restrict the requested access to trusted users only.
For example, HKEY_LOCAL_MACHINE only grants KEY_WRITE to administrators and
SYSTEM—an application that requests KEY_WRITE to HKEY_LOCAL_MACHINE will
not work with UAC enabled.
Use of Windows privileges that have security ramifications, such as
SE_DEBUG_PRIVILEGE, which allows the debugging of other users' processes and
is granted only to administrators.
Important
There are two approaches you can take to utilize Standard User Analyzer: launch
your application as standard user or launch your application elevated as an
administrator.
Launch your application as standard user. In this instance, the Standard User
Analyzer is running in diagnosis mode. The application will fail at the first error it
encounters and the Standard User Analyzer will report why it failed.
Launch your application elevated as an administrator. In this instance, the
Standard User Analyzer is running in prediction mode. The application will be
able to run through its course and the Standard User Analyzer will predict and
give an overview of the errors the application might encounter if it is run as
standard user.
Once the bugs are fixed and resolved, perform this procedure once more as a
standard user without the Standard User Analyzer to ensure your application is
working as expected on Windows Vista.
2. Click Start, click All Programs, and then click Standard User Analyzer.
3. In the Standard User Analyzer, for Target Application, specify the full directory
path for an application to test or click the Browse button to locate the program's
executable file with Windows Explorer.
4. Click Launch and then click Continue at the User Account Control dialog box.
5. After the test application launches, perform standard administrative tasks in the
application, and close the application when you have completed.
6. In the Standard User Analyzer, examine the output on each tab. Use this data
to identify the compatibility issues that the program might have.
Check where the settings are stored in the registry. If any settings are stored in
HKLM, the application or control panel will most likely require an administrator access
token.
If any of the settings are per-computer, the application or control panel will require an
administrator access token.
If any of the settings do anything in other users’ profiles, the application or control
panel will require an administrator access token.
Note
This course should not be taken lightly. Be cautious not to compromise the
overall security of the system by lowering the control afforded by the ACL.
Is it possible to change the user interface to set per-user state rather than global
state (and do not expose global state modification through the user interface)?
In Windows Vista, these changes require that applications be marked with information
that allows the operating system to determine in what context the application should be
launched. For example, standard user applications need to be marked to run as the
invoker, and accessibility-enabled applications need to be identified by the system.
Setup
Never perform administrative actions (such as completing the setup process) on first
run; it should be done as part of the initial setup process.
Never write directly to the Windows directory or subdirectories. Use the correct
methods for installing files such as fonts.
If you need to automatically update your application, use a mechanism suitable for
use by standard users, such as Windows Installer 4.0 User Account Control patching
to accomplish the update.
Saving State
Do not write per-user information or user-writable information to Program Files or
Program directories.
Do not use hard-coded paths in the file system. Take advantage of the KnownFolders
API and ShGetFolder to find where to write data.
sei.cbSize = sizeof(SHELLEXECUTEINFOW);
sei.hwnd = hWnd;
sei.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
sei.lpVerb = _TEXT("runas");
sei.lpFile = lpFile;
sei.lpParameters = lpParameters;
sei.nShow = SW_SHOWNORMAL;
if ( ! ShellExecuteEx ( &sei ) )
{
printf( "Error: ShellExecuteEx failed 0x%x\n", GetLastError() );
return FALSE;
}
return TRUE;
}
The following code sample illustrates how to pass HWND with CreateElevatedComObject
by using the elevation moniker. It assumes that you have already initialized COM on the
37
current thread. More information about the elevation moniker is available in Step Four of
this document.
HRESULT CreateElevatedComObject(HWND hwnd, REFCLSID rclsid, REFIID riid, __out
void ** ppv)
{
BIND_OPTS3 bo;
WCHAR wszCLSID[50];
WCHAR wszMonikerName[300];
The only addition is an HWND field, hwnd. This handle represents a window that
becomes the owner of the elevation UI when secure desktop prompting is enabled.
The following code sample illustrates how to pass HWND in managed code to ensure
that parent dialogs are aware of the HWND and its use.
System.Diagnostics.Process newProcess = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo info = new
System.Diagnostics.ProcessStartInfo(“D:\SomeProgram.exe”);
info.UseShellExecute = true;
info.ErrorDialog = true;
info.ErrorDialogParentHandle = this.Handle;
newProcess.StartInfo = info;
newProcess.Start();
path, both standard users and administrators would have to respond to a User Account
Control dialog box on every log on. Windows Vista notifies the user if an application has
been blocked by placing an icon in the system tray. The user can then right-click this icon
to run applications that were blocked from prompting for elevation as the user logged on.
The user can manage which startup applications are disabled or removed from this list by
double-clicking on the tray icon.
A C++ code sample illustrating how to use Task Scheduler to perform the elevation for
the user is available in the References section of this document.
Important
Be aware that runas does not provide the ability to launch an application with an
elevated access token, regardless of whether it is a standard user with privileges
like a Backup Operator or an administrator. The runas command grants the user
the ability to launch an application with different credentials. The best method to
use to launch an application with a different account is to perform the action
programmatically by using a service and not rely on the user to run the
component as a different user. If your program programmatically uses the runas
command, ensure that it is not intended to launch an elevated process.
If your application will require the user to run parts of the application with a different user
account, ensure that the runas command with the command prompt option is exposed.
The following table details the available parameters for the runas command.
39
Runas parameters
Parameter Description
Examples:
runas /noprofile /user:mymachine\Denise cmd
Notes:
Enter the user's password only when prompted.
The /profile parameter is not compatible with the /netonly parameter.
The /savecred parameter is not compatible with the /smartcard parameter.
40
Other APIs that Are Re-directed to HKLM Registry Values and Virtualization will
Apply
WritePrivateProfileString(,,,”system.ini”);
CheckSectionAccess(“system.ini”,…);
Important
Simply refractoring your application's user interface will not fulfill the
requirements for UAC compatibility. Your application's core functionality must
comply with the Windows Vista standard user model requirements. These
requirements were detailed in the previous step, Step Three: Redesign Your
Application's Functionality for UAC Compatibility.
administrators to give permission for certain administrative tasks within the currently
logged in session.
Design Goals
The following list comprises the UAC design goals.
Be Predictable
Administrators need to know which tasks require elevation. If they cannot predict the
need for elevation accurately, they are more likely to give consent for administrative tasks
when they should not. Standard users need to know which tasks require an administrator
to perform or cannot be performed at all in managed environments.
Elevation Prompt
The elevation prompt is built upon an existing Windows user interface. The elevation
prompt displays contextual information about the executable requesting elevation, and
the context is different depending on whether the application is Authenticode signed or
not. The elevation prompt is seen in two variations: the consent prompt and the credential
prompt.
Consent Prompt
The consent prompt is displayed to administrators in Admin Approval Mode when they
attempt to perform an administrative task. This is the default user experience for
administrators in Admin Approval Mode and can be configured in the local Security Policy
Manager snap-in (secpol.msc) and with Group Policy.
The following figure is an example of a User Account Control consent prompt.
Credential Prompt
The credential prompt is displayed to standard users when they attempt to perform an
administrative task. This is the default user experience for standard users and can be
configured in the local Security Policy Manager snap-in (secpol.msc) and with Group
Policy.
The following figure is an example of a User Account Control credential prompt.
44
1. Elevation entry point (for example, a control or link that displays the UAC shield icon).
2. Elevation prompt (a request for consent or for administrator credentials).
3. Elevated process.
The following example workflow summarizes how the preceding components are related:
1. An administrator in Admin Approval Mode logs on to a Windows Vista computer.
2. The user then decides to add another administrator user for the computer.
3. The user clicks Start, clicks Control Panel, and then clicks the link in the Security
section entitled Allow a program through Windows Firewall, which is displayed
inline with a shield icon.
4. A consent prompt appears requesting the user for approval.
5. The user clicks Continue and the elevated process is created.
6. In Windows Firewall Settings, the user modifies the Windows Firewall settings and
then clicks OK, which terminates the elevated process.
7. The user continues to work on the computer as a standard user.
Note
Elevation entry points do not remember state (e.g. when navigating back from a
shielded location or task), as well as the entry point will not remember that
elevation has occurred. As a result, the user will need to re-elevate to enter the
task/link/button again.
Shield Icon
The shield icon is the primary user interface decoration for a UAC elevation point. This
icon signifies security related activities in Windows Vista and previous versions of
Windows, and this relationship is continued in Windows Vista.
The following figure is an example of the shield icon.
Shield icon
The shield icon will play a critical part in all three components of the UAC user
experience.
46
When viewing the system with Windows Explorer, any application that is marked to
request an administrator access token when it is launched will automatically be decorated
with a shield glyph over its icon. This permits users to know which applications, when
launched, will request elevation.
Shield icon properties:
Consistent appearance throughout the entire UAC user experience.
Does not reflect any visual state (e.g. active, hover, disabled, etc.).
Does not remember state.
There are three consistent control styles that an entry point marked with a shield icon can
take within the user experience:
UAC button
UAC hyperlink
UAC command link
These styles apply to all scenarios where these user interface elements can appear such
as Wizards, Property Pages, Control Panel Framework, Explorers, etc. Each of the styles
implies that an elevation prompt will immediately be displayed after the user clicks a UAC
user interface control.
A fourth UAC user interface entry point, the UAC icon overlay, is also discussed in this
section. Whether an executable receives an icon overlay or not is not controlled by the
application developer. Windows Vista overlays a shield icon on applications' icons for
executables that have requestedExecutionLevel set to requireAdministrator.
UAC Hyperlink
The UAC hyperlink should be used in any user interface hyperlink that, when clicked, will
require the elevation prompt to prompt the user for approval or credentials.
A UAC hyperlink consists of the following components:
Shield icon
Hyperlink control
The UAC hyperlink is not packaged with the shield icon for a developer to use.
Developers will need to get the shield icon resource and render it next to the hyperlink.
The following screenshot is an example of a UAC hyperlink.
UAC hyperlink
Icon Overlays
In Windows Vista, if an executable file requires elevation to launch, then the executable's
icon should be “stamped” with a shield icon to indicate this fact. The executable's
application manifest must mark “requireAdministrator” to designate the executable as
requiring a full administrative access token. The shield icon overlay will also be
automatically placed on executables that are deemed to require elevation as per the
installer detection heuristics. For example, a file named setup.exe will automatically
receive a shield icon overlay even if the executable does not have an embedded
application manifest.
The following figure is an example of a UAC icon overlay.
Note
Guidance about how to create and embed an application manifest with an
executable is provided in the Create and Embed an Application Manifest with
Your Application section of this document.
49
Icon API
Button Button_SetElevationRequired(hwndButton)
How do I…
Add a shield icon to the user interface?
Add a shield icon to a button?
Add a shield icon to a Windows Installer button?
Add a shield to a "Next" button control on a Wizard?
Add a shield icon to a task dialog button?
Elevate a modal dialog?
Note
Generally, you should not add the shield icon directly to your user interface.
Using one of the proceeding methods of imbedding the shield icon in a control is
recommended. Additionally, simply adding a shield icon in your user interface will
not ensure UAC compatibility. You must also refractor the entirety of your
application's user experience (add a requestedExecutionLevel, fix any standard
user bugs, and ensure the user interface is user friendly and UAC compatible).
Note
hwndButton is the HWND of the button; fRequired determines whether to show
(TRUE) or hide (FALSE) the UAC shield icon.
Important
Displaying the UAC shield icon the "Next" button is only supported in
AeroWizards (PSH_AEROWIZARD).
To display the shield icon on the "Next" button for a specific page in an
AeroWizard, use the following code:
case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_SETACTIVE)
{
// Show next button
//
51
SendMessage(GetParent(hwndDlg),
PSM_SETWIZBUTTONS,
PSWIZBF_ELEVATIONREQUIRED,
PSWIZBF_NEXT);
Caution
A task dialog button should never require a UAC shield icon. The “press” action
on a task dialog button is expected to commit/cancel and dismiss the task dialog.
It would be strange for such a button to then display the elevation prompt to the
user.
Note
A version of this API that is more complicated to call is available. A simplified
version will be available in a later version of Windows Vista.
Note
If you have links to other administrator user interface in your administrator-only
user experience, the user interface will launch its target elevated. Therefore, you
do not need to put any shields in an application that is solely administrative.
The developer must call into the UAC elevation process when the OnClick event for
the shield icon is detected.
The following list details benefits of properly designing an elevated process or COM
object:
This is the best overall user experience for both user types. The user interface will
launch, viewable to everyone, and all UAC functionality on that user interface will be
accessible to everyone. Only when an administrator task is required does the user
attempt to elevate to complete the task.
Doing this work now will make you fully UAC–compliant moving forward.
The user interface/COM separation is a good architectural practice.
Clicking on a shield icon causes the application to launch either an elevated program or
an elevated COM object to perform the task.
Administrator-only Application
In this instance, the application’s initial launch requires administrator approval. This
method is called "prompt before launch". Once launched, the application is running with a
full administrative access token and can therefore perform the desired administrative
tasks. This method is the least work for the developer. The application’s manifest is
marked with a requestedExecutionLevel of requireAdministrator.
Important
While this does require the least amount of work for the developer, please note
that, just like other administrative applications in Windows Vista, administrators
will have to elevate in order to use this application and that standard users will be
unable to use the application.
The following list details requirements for administrator-only applications:
The application manifest should contain a requestedExecutionLevel marking set to
requireAdministrator.
The user is prompted for administrator approval prior to Windows launching the
application with a full administrative access token.
The following list details benefits of properly designing an administrator-only application:
The operating system does not have to "guess" if your setup application is an
administrative application.
Standard users will automatically be given a hint that the operation is an
administrative operation. For example, when you see the icon for an application
marked requireAdministrator, the icon has a shield embedded in the icon.
On Windows Vista, if you mark your application as requireAdministrator you know
that, once it is launched, it will be running with a full administrator access token.
54
Note
Marking an application requireAdministrator does NOT silently elevate the
application. The user will still have to give elevation consent to start the
application. There is no way to mark an application in Windows Vista to silently
elevate.
The following list details points of consideration for designing an administrator-only
application:
This user experience means that all users will see an elevation prompt (either the
credential prompt or the consent prompt) prior to the user interface even being
visible. That also means no one is able to simply view the current settings until after
authenticating with administrator credentials
If you are marking requireAdministrator on a setup application, you should be aware
that the user that is running the setup is different from the user that may user the
application. Therefore, you should not modify HKEY_CURRENT_USER (HKCU) and
other per-user settings, such as writing to the user profile, during your administrative
setup.
Important
You must assume that the user running the administrative application is different
from the normal user on the computer.
Executables that require an administrator access token are marked with a shield icon
overlay.
Mixed Application
A mixed application is one that can be run by users—all users of the system (standard
users, administrators in Admin Approval Mode, and those in between like Backup
Operators). This is also a "prompt before launch" application. The application will run with
the invoker's access token and will launch normally for standard users (no elevation
prompt).The program must then modify its behavior at run time to disable those features
that would not be available to the user based on the administrative access token
obtained.
A mixed application does not have the ability to obtain additional administrative privileges
once launched; therefore, it does not provide the flexibility of the elevated process or
COM object method described previously. This is most useful for applications that require
an access token above that of a standard user, but less than a full administrator.
For example, the Microsoft Management Console (MMC) is marked highestAvailable. If a
true standard user runs the MMC, MMC will launch as a standard user application without
55
any elevation attempt or prompt. If the user is a "split token" user, such as an
administrator in Admin Approval Mode or a Backup Operator, the operating system will
prompt the user to get consent to launch MMC with the user's "highest" available
privilege. In the case of a standard user who has Backup Operator privileges, after
elevation, MMC will be launched with standard user + Backup Operator, but nothing
more. If an administrator launches MMC, after elevation, MMC will be running as a full
administrator application.
The benefit of properly designing a mixed application is that the application is available to
all users of the system, even though some functionality may be disabled.
The following list details points of consideration for designing mixed applications:
The developer must dynamically change the behavior of the application based on the
administrative Windows privileges and user rights available from the user.
The standard user is prevented from ever being able to act on the administrative-
level functions on the user interface. There is no potential for prompt elevation once
the program is running (the administrators must elevate before opening the user
interface).
Note
There is one workaround for the previous bullet point. An administrator can
launch an elevated command prompt on the standard user's computer and run
the application from the command prompt. For example, right-click the command
prompt, select Run as administrator, and then type "applicationname.exe" in
the command prompt.
The user experience is branched between the standard user and the administrator in
Admin Approval Mode.
Note
The administrative executable program may enable inter-process communication
with a standard user executable using shared memory, local RPC, or named
pipes. If the administrative program does enable communication with the
standard user executable, the developer needs to use good security practice to
validate all inputs from the lower privilege program.
Note
There is no communication channel between the two programs once the second
program launches
The following list details uses for the admin broker model:
Wizards – When the Hardware Wizard realizes that the required driver is not installed
on the computer or located in the enterprise's approved location, it needs an elevated
application with the ability to move a driver into the computer store.
Autorun.exe calling Setup.exe – The first time you put in a game CD, the required
operation from autorun.exe is to set up the application. The second time you insert
the CD, the default operation is to play the game.
A benefit to using the admin broker model is that it is probably the easiest mechanism to
implement for the developer.
The following list details some drawbacks to using the Admin Broker Model:
The transitions from application to application can be confusing to the user. It can be
hard to keep the user apprised of why a new application is “popping up” on the
monitor.
In addition, state is harder to pass between these two applications. For example, you
would not use this to pass state between a standard user control panel (CPL) and its
57
administrator counterpart simply to allow the same CPL to have administrative and
non-administrative functionality. The standard user CPL would have to store its state
somewhere.
Often, there is a lot of replicated code when splitting the functionality between two
programs.
To implement the admin broker model, create two programs (one standard user and one
administrative), mark them with the appropriate manifest requestedExecutionLevel, and
launch the administrative program from the standard user program using ShellExecute().
The following list details some drawbacks to using the admin COM object model:
Requires the most work for the developer as each application feature has to be
evaluated and tested for administrator functionality and that function has to be
provided by a back-end COM object.
User needs to provide elevation approval.
The resulting "unit" of standard user application and Admin backend COM object is
now "drivable" and is not protected by UIPI and other isolation mechanisms.
To implement the admin COM object model, create a standard user front-end application
and launch elevated back-end COM objects to perform administrative tasks.
not place information in the correct location are likely to fail. This is especially true
when virtualization is turned off.
4. Use a consistent folder location when installing shared components. Shared
components should be installed to the Common Files directory by using the
CommonFilesFolder property in the Directory table of your Windows Installer
package. Managing shared components can be problematic and should be avoided,
if possible. A developer who does not install shared components consistently can end
up with Component Object Model (COM) registration information pointing to older
components. Windows Installer Merge Modules (MSM) is specifically designed to
enable shared components to consistently install in the context of all packages that
install the shared component. Other problems arise when modifications of shared
components cause existing applications to fail. One way to address this issue is for
applications to be built using Microsoft .NET– or Win32–versioned assemblies.
5. Perform setup rollback if an installation fails. Partially installed software can fail in
strange and unexpected ways providing for a poor user experience. Windows
Installer supports this rollback feature.
6. Do not install application shortcuts all over the user’s profile. While it may be
tempting to add your application icon to every known exposure point in Windows, it
often results in users feeling that they have lost control of their computer. Users are
then forced to manually remove these shortcuts to return the computer to a desired
look and feel. If the developer wants to add icons to the desktop, ask the user for
permission during the installation. Windows Vista addresses discoverability of
applications post install and the most recently used application list to avoid large Start
menu traversing.
7. Avoid automatically launching background applications at user logon. Although
it is possible to add programs to the startup group or Run key during installation, it
adds overhead to the system. Over time, the performance of the user’s system can
significantly degrade. If your application can benefit from a background task, allow it
to be user-configurable. Also, adding a startup task via the HLKM run key may
prevent a standard user account from modifying the behavior in the future. If the user
wants an application to launch at login time, store the information in the run key of
HKCU.
8. Follow clean removal logic. A user might remove an application not only to free up
disk space, but also to return the computer to its state prior to the application being
installed. The application’s uninstall process should correctly and fully remove the
application. Windows Installer defaults to the following rules:
All non-shared application files and folders.
Shared application files whose reference count (refcount) reaches zero.
Registry entries, except for keys that might be shared by other programs.
60
All shortcuts from the Start menu that the application created at the time of
installation.
User preferences may be considered user data and left behind, but an option to
do a completely clean removal should be included.
The uninstaller itself (if not using Windows Installer).
Note
In future releases, the ONLY way to run an application elevated will be to have a
signed manifest that identifies the privilege level the application needs.
Note
Hosting applications can become standard user or administrator-only
applications only if they support that certain type of hosted application. For
example, MMC.exe now only hosts administrative snap-ins, and Explorer.exe
only hosts standard user code.
System behavior
Unmarked Yes
asInvoker No
requireAdministrator No
highestAvailable No
This section details the behavior of the elevation prompt depending on the parent
process access token, the setting for the User Account Control: Behavior of the
elevation prompt for administrators in Admin Approval Mode policy and the User
Account Control: Behavior of the elevation prompt for standard users policy, and
the requested execution level marking for the application.
Whether an application can run and which user rights and administrative Windows
privileges it can obtain are dependent on the combination of the application’s requested
execution level in the application compatibility database and the administrative privileges
available to the user account that launched the application. The following tables identify
the possible run-time behavior based on such possible combinations.
Application launch behavior for a standard user with additional privileges (E.G.
Backup Operator)
uiAccess Values
Value Description
Value Description
Important
Applications with the uiAccess flag set to true must be Authenticode signed to
start properly. In addition, the application must reside in a protected location in
the file system. \Program Files\ and \windows\system32\ are currently the two
allowable protected locations.
Manifest File
To mark your application, first create a manifest file to use with the target application. This
can be done using any text editor. The manifest file should have the same name as the
target.exe with a .manifest extension.
Example
Executable: IsUserAdmin.exe
Manifest:IsUserAdmin.exe.manifest
Sample application manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="IsUserAdmin"
type="win32"/>
66
The parts of the manifest that need to be adjusted for your application are marked in
bold. They include the following:
The assembly identity
The name
The type
The description
The attributes in the requestedExecutionLevel
After rebuilding the application, the manifest should be embedded in the resource section
of the executable.
67
C or C++ Project
The following procedure details how to create a manifest for a C or C++ project type in
Visual Studio 2005.
Note
The updated manifests that include explicit version tags will permit the
application to run correctly on both Windows Vista and Windows XP.
68
To insert a default manifest file into the target executable with mt.exe
1. Use a text editor, such as Windows Notepad, to create a default manifest file,
temp.manifest.
2. Use mt.exe to insert the manifest. The command would be: mt.exe –manifest
temp.manifest –outputresource:YourApp.exe;#1
Note
The IDE does not currently include a post-build option for a Visual Basic
application.
Place the following line as a post build task in Project Properties:
mt.exe -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$
(TargetDir)$(TargetName).exe;#1"
Note
You will need a commercial certificate if you with your application to be trusted on
the target computer of a customer installing your application.
If you use the makecert.exe file to generate your signing key pair, be aware that it only
generates a 1024-bit key. Authenticode signatures should be at least a 2048-bit key. The
makecert.exe file should only be used for testing purposes.
The following procedure details the high level requirements for using makecert.exe to
generate your signing key pair. An example and makecert.exe parameters follow this
procedure.
makecert.exe parameters
Parameter Description
/ss StoreName The certificate store name that will store the
test certificate. Example: PrivateCertStore
For more information about Authenticode signatures, see the MSDN Web site, for
example:
71
administrator or higher privileges to install and that the user will always run the latest
version as long as the computer is connected to the network. It also places some limits
on an IT professional's ability to control the installation of these applications.
ClickOnce (http://go.microsoft.com/fwlink/?LinkId=71500) deployment is a Microsoft .NET
installation technology that automatically installs and configures a client-side application
when a user clicks a manifest link, such as a manifest in a Web site, on a CD, or on a
universal naming convention (UNC) path. By default, the application will copy itself to the
Temporary Internet Files folder and run within a restricted environment.
Note
Even if your application has been signed with the IT strong name that gives it Full
Trust, you still cannot do anything that requires administrator permissions, such
as access certain parts of the file system and registry. ClickOnce applications
however, are targeted as per-user applications, so this should not be a problem.
Important ClickOnce should not be used for deploying applications that perform
administrative operations.
Resolution
Removing the ActiveX control from the application almost always results in a loss of
functionality. Therefore, this is not recommended for remediation unless the ActiveX
control is providing some visual or functional enhancement that is not part of the site's
core functionality. For example, a stock ticker on a non-stock–related portal.
74
In most cases, packaging the ActiveX control for installation by SMS or Group Policy is
the correct solution. However, most of the controls will not be included in the base image,
so Web sites must modify their pages to fail gracefully. This should comprise detecting
the missing ActiveX control and redirecting to the Managed Desktop software request
page.
Resolution
Since Visual Basic 4 and Visual Basic 5 are deprecated, Microsoft recommends that you
replace the application. It should be possible to install the ActiveX document as part of a
client installation; however, updates to the document will be restricted without
redeployment through SMS or Group Policy.
Resolution
Once the dependencies are identified, they can either be packaged with the base image
or made available through on-demand SMS installation. The application might have to
change how it notifies the end user of the missing software, directing the user to the SMS
installation site instead of to the manufacturer.
Note
You can also "push" the patch with SMS or Group Policy in conjunction with the
Add or Remove Programs (ARP) control panel. the user selects software to
install and the system installer does the rest—the user does not have to be an
administrator. For initial installations, this can be dealt with by packaging the
software for an installation agent to push out. However, some applications rely on
frequent automatic updates that may not align well with a centrally managed
application model.
Applications that detect updates and attempt to patch themselves will be unable to do so
as they will not have permission to modify files in the system directories.
Resolution
Package your application/patch for deployment by SMS. Applications can still detect
that an upgrade is available (as long as they do it without requiring administrative
permissions) and can redirect to the provisioning site.
Question whether your application needs elevated computer permissions, such as file
system, registry access, or COM interoperability. If not, then it might be possible to
rewrite the application as a ClickOnce deployment package, which will run in the
Microsoft .NET sandbox.
Convert to a Web application without any client-side dependencies.
Note
A user's Documents folder is no longer stored under Documents and Settings.
In Windows Vista, a new root directory on the file system called Users now
contains the profiles for users of the computer.
Because these directories have changed, developers are encouraged to use CSIDLs to
locate the path to specific well-known directories in a system-independent way. For more
information, see the MSDN article on CSIDLs (http://go.microsoft.com/fwlink/?
LinkId=71501).
76
An application needs write access to the file system. When running under a managed
desktop, an application only has write permission to the following folders and their
children.
CSIDL_PROFILE
CSIDL_COMMON_APPDATA
Note
Standard users cannot write to Users\Common.
C:\Users\Common>cd "Application Data"
C:\Users\Common\Application Data>echo File > File.txt
C:\Users\Common\Application Data>
Applications should not attempt to write to other locations, such as the following:
C:\Windows.
C:\Windows\System32.
Program Files\{application}.
C:\{application}.
Note
This will work if the user created the folder, which members of the Users group
can do by default.
An application is trying to specifically create C:\Users\Profiles\{user} is not allowed since
the user can only create folders under C:\Users\{user}. The location chosen appears to
be confused based on where Microsoft has stored the Documents folder on previous
versions of the operating system.
Application settings that need to be changed at run time should be stored in one of the
following locations:
CSIDL_APPDATA
CSIDL_LOCAL_APPDATA
CSIDL_COMMON_APPDATA
Documents saved by the user should be stored in the CSIDL_MYDOCUMENTS folder.
All paths should not be hard-coded but should use the Environment.GetFolderPath()
function.
permissions. In addition, some applications do not respond well when the code to write
the file fails because as a result of an access denied from the operating system.
Resolution
Assume that users can only write to their own profiles. For documents intentionally saved
by users, initialize the dialog boxes to start at Documents
(Environment.GetFolderPath(Environment.SpecialFolder.Personal). Remember that the
Save dialog box will allow a user to browse to other locations than the user's profile, so
the application should include logic to ensure that it fails gracefully if a user choose a
different directory than those located in his/her profile.
References
This section includes a virtualization reference and a security settings reference.
Virtualization Reference
File virtualization
Virtualize (%SYSTEMROOT%, %PROGRAMDATA%, %PROGRAMFILES%\
(Subdirectories)
Redirect to: %LOCALAPPDATA%\VirtualStore
Excluded binary executables: .exe, .dll, .sys
Registry Virtualization:
Virtualize (HKLM\SOFTWARE)
Redirect to: HKCU\Software\Classes\VirtualStore\MACHINE\SOFTWARE\
<Application Registry Keys>
Keys excluded from virtualization
HKLM\Software\Classes
HKLM\Software\Microsoft\Windows
HKLM\Software\Microsoft\Windows NT
Applicability
Virtual stores do not roam
Corresponding global objects would not roam
Enabled only for interactive standard users
78
Note
The procedures presented in this section are intended for administering
unmanaged computers. To use Group Policy to administer the settings centrally
in a managed environment, use Active Directory Users and Computers (dsa.msc)
instead of local Security Policy Manager snap-in (secpol.msc).
The following procedure details how to configure the UAC security settings with the
Group Policy. The procedure details the default user experience for an administrator in
Admin Approval Mode.
To view/set the UAC security settings with the Group Policy Object Editor
1. Click the Start button, type gpedit.msc into the search box, and then press
79
Enter.
2. At the User Account Control consent prompt, click Continue.
3. In Group Policy, expand User Configuration, and then expand Security
Options.
4. Right-click the security setting that you would like to change and select
Properties.
User Account Control: There are two possible Disabled for new
Admin Approval Mode for settings: installations and for
the built-in Administrator Enabled - The built-in upgrades where the
account. Administrator will be run built-in Administrator is
as an administrator in NOT the only local
Admin Approval Mode. active administrator on
the computer. The
Disabled - The
built-in Administrator
administrator runs with a
account is disabled by
full administrator access
default for installations
token.
and upgrades on
domain-joined
computers.
Enabled for upgrades
when Windows Vista
determines that the
built-in Administrator
account is the only
active local
administrator on the
computer. If Windows
Vista determines this,
the built-in
Administrator account
is also kept enabled
following the upgrade.
The built-in
Administrator account
is disabled by default
for installations and
upgrades on domain-
joined computers.
81
User Account Control: There are three possible Prompt for consent
Behavior of the elevation values for this setting:
prompt for administrators in Elevate without
Admin Approval Mode prompting: Silently
elevate.
Prompt for credentials:
Require users to enter
their login password
before continuing.
Prompt for consent: Ask
the user for approval
before elevating. This is
the default setting.
This setting determines how
the user is prompted prior to
running a program with
higher permissions. This
policy is only in effect when
UAC is enabled.
82
User Account Control: Determines how the user is Prompt for credentials
Behavior of the elevation prompted prior to running a
prompt for standard users program with higher
permissions. This policy is
only in effect when UAC is
enabled. The following are
the available configuration
options for this setting:
Automatically deny
elevation requests: Users
will not be prompted
when an application
wants to perform an
administrative task. The
application will fail to
launch and will present
an access denied, or
equivalent, error to the
user.
Prompt for credentials:
Require users to enter
their login password
before continuing.
Note
For most situations, the Elevate without prompting option is NOT
recommended. Elevating without prompting would permit applications running as
a standard user to launch administrative applications without user consent and
effectively bypass UAC.
86
/****************************************************************************
* Main.cpp - Sample application for Task Scheduler V2 COMAPI *
Component: Task Scheduler
* Copyright (c) 2002 - 2003, Microsoft Corporation
* This sample creates a task to at the time registered to start the desired task.
*
****************************************************************************/
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <comdef.h>
#include <comutil.h>
//Include Task header files - Included in Windows Vista Beta-2 SDK from MSDN
#include <taskschd.h>
#include <conio.h>
#include <iostream>
#include <time.h>
#define CLEANUP \
pRootFolder->Release();\
pTask->Release();\
CoUninitialize();
wstrExecutablePath = argv[1];
}
HRESULT CreateMyTask(LPCWSTR wszTaskName, wstring wstrExecutablePath)
{
// ------------------------------------------------------
// Initialize COM.
TASK_STATE taskState;
int i;
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}
if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
88
return 1;
}
// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CreateElevatedComObject( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}
// Check if the same task already exists. If the same task exists, remove it.
hr = pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the trigger collection to insert the registration trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
CLEANUP
return 1;
}
// ------------------------------------------------------
// Add an Action to the task.
IExecAction *pExecAction = NULL;
IActionCollection *pActionCollection = NULL;
{
printf("\npActionCollection->Create failed: %x", hr );
CLEANUP
return 1;
}
// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE,
_variant_t(_bstr_t( L"S-1-5-32-545")),//Well Known SID for \\Builtin\Users group
_variant_t(),
TASK_LOGON_GROUP,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
91
// Clean up.
CLEANUP
CoUninitialize();
return 0;
}