Redirects a known folder to a new location.
HRESULT SHSetKnownFolderPath( _In_ REFKNOWNFOLDERID rfid, _In_ DWORD dwFlags, _In_ HANDLE hToken, _In_ PCWSTR pszPath );
- rfid [in]
A GUID that identifies the known folder.
- dwFlags [in]
Either 0 or the following value.
- hToken [in]
An access token used to represent a particular user. This parameter is usually set to NULL, in which case the function tries to access the current user's instance of the folder. However, you may need to assign a value to hToken for those folders that can have multiple users but are treated as belonging to a single user. The most commonly used folder of this type is Documents.
The calling application is responsible for correct impersonation when hToken is non-null. It must have appropriate security privileges for the particular user, including TOKEN_QUERY and TOKEN_IMPERSONATE, and the user's registry hive must be currently mounted. See Access Control for further discussion of access control issues.
Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHSetKnownFolderPath to set folder locations (such as the Desktop folder) for the Default User. The Default User user profile is duplicated when any new user account is created, and includes special folders such as Documents and Desktop. Any items added to the Default User folder also appear in any new user account. Note that access to the Default User folders requires administrator privileges.
- pszPath [in]
A pointer to the folder's new path. This is a null-terminated Unicode string of length MAX_PATH. This path cannot be of zero length.
Returns S_OK if successful, or an error value otherwise, including the following:
Among other things, this value can indicate that the rfid parameter references a KNOWNFOLDERID that is not present on the system. Not all KNOWNFOLDERID values are present on all systems. Use IKnownFolderManager::GetFolderIds to retrieve the set of KNOWNFOLDERID values for the current system.
This function replaces SHSetFolderPath. That older function is now simply a wrapper for SHSetKnownFolderPath.
The caller of this function must have Administrator privileges. To call this function on public known folders, the caller must have Administrator privileges. For per-user known folders the caller only requires User privileges.
Some of the known folders, for example, the Documents folder, are per-user. Every user has a different path for their Documents folder. If hToken is NULL, the API tries to access the calling application's instance of the folder, which is that of the current user. If hToken is a valid user token, the API tries to impersonate the user using this token and tries to access that user's instance.
To call this function on a folder of type KF_CATEGORY_COMMON, the calling application must be running with elevated privileges.
Minimum supported client
|Windows Vista [desktop apps only]|
Minimum supported server
|Windows Server 2008 [desktop apps only]|
Build date: 11/28/2012