GetUserProfileDirectoryA function (userenv.h)

Retrieves the path to the root directory of the specified user's profile.

Syntax

USERENVAPI BOOL GetUserProfileDirectoryA(
  [in]            HANDLE  hToken,
  [out, optional] LPSTR   lpProfileDir,
  [in, out]       LPDWORD lpcchSize
);

Parameters

[in] hToken

Type: HANDLE

A token for the user, which is returned by the LogonUser, CreateRestrictedToken, DuplicateToken, OpenProcessToken, or OpenThreadToken function. The token must have TOKEN_QUERY access. For more information, see Access Rights for Access-Token Objects.

[out, optional] lpProfileDir

Type: LPTSTR

A pointer to a buffer that, when this function returns successfully, receives the path to the specified user's profile directory.

[in, out] lpcchSize

Type: LPDWORD

Specifies the size of the lpProfileDir buffer, in TCHARs.

If the buffer specified by lpProfileDir is not large enough or lpProfileDir is NULL, the function fails and this parameter receives the necessary buffer size, including the terminating null character.

Return value

Type: BOOL

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

Remarks

The following is an example of the path returned by GetUserProfileDirectory in Windows XP:

C:\Documents and Settings\Joe

The following is an example of the path returned by GetUserProfileDirectory in Windows 7:

C:\Users\Joe

To obtain the paths of subdirectories of this directory, use the SHGetFolderPath (Windows XP and earlier) or SHGetKnownFolderPath (Windows Vista) function.

Note

The userenv.h header defines GetUserProfileDirectory as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

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

GetAllUsersProfileDirectory

GetDefaultUserProfileDirectory

GetProfilesDirectory

User Profiles Overview

User Profiles Reference