UnloadUserProfile function (userenv.h)

Unloads a user's profile that was loaded by the LoadUserProfile function. The caller must have administrative privileges on the computer. For more information, see the Remarks section of the LoadUserProfile function.

Syntax

USERENVAPI BOOL UnloadUserProfile(
  [in] HANDLE hToken,
  [in] HANDLE hProfile
);

Parameters

[in] hToken

Type: HANDLE

Token for the user, returned from the LogonUser, CreateRestrictedToken, DuplicateToken, OpenProcessToken, or OpenThreadToken function. The token must have TOKEN_IMPERSONATE and TOKEN_DUPLICATE access. For more information, see Access Rights for Access-Token Objects.

[in] hProfile

Type: HANDLE

Handle to the registry key. This value is the hProfile member of the PROFILEINFO structure. For more information see the Remarks section of LoadUserProfile and Registry Key Security and Access Rights.

Return value

Type: BOOL

TRUE if successful; otherwise, FALSE. To get extended error information, call GetLastError.

Remarks

Before calling UnloadUserProfile you should ensure that all handles to keys that you have opened in the user's registry hive are closed. If you do not close all open registry handles, the user's profile fails to unload. For more information, see Registry Key Security and Access Rights and Registry Hives.

For more information about calling functions that require administrator privileges, see Running with Special Privileges.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header userenv.h
Library Userenv.lib
DLL Userenv.dll

See also

LoadUserProfile

PROFILEINFO

User Profiles Overview

User Profiles Reference