Check Operations in Advance When Installing
[This is preliminary documentation and subject to change.]
Requirement (Designed for Microsoft® Windows® Logo)
The installer must check before starting any operation to ensure that it can complete that operation. The following are requirements based on this principle:
-
Installers must fail gracefully in the case where a system component cannot be replaced because file system security prevents an existing file from being overwritten. For example, installers that must overwrite system files should check up-front if the current user is a member of the administrator's local group. This will avoid confusion later by preventing the user from getting file copy errors from which there is no recovery.
-
Applications must be tested on Windows NT under non-administrator accounts. An application must run under a user account, but that user must not be able to change the application setup configuration.
-
When installing the application, the installer must check for the user privilege level. If the user is not an administrator and the application will work but with limited functionality, the installer must warn the user that only limited functionality will be available since they do not have administrator privileges; the installer must allow them to discontinue the installation.
Remarks
The following sample code checks for user privilege level.
//----------------------------------------------------------
// IsAdmin - tests to see if the current user is an admin
//----------------------------------------------------------
BOOL IsAdmin( )
{
SC_HANDLE hSC;
// Try an Admin Privileged API - if it works, return TRUE, else FALSE
hSC = OpenSCManager(
NULL,
NULL,
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE );
if ( hSC == NULL )
return FALSE;
CloseServiceHandle( hSC );
return TRUE;
}
See Also
For more information about how to check the user privilege level, see KB article PSS ID# Q118626.