Redirects a known folder to a new location.
HRESULT SHSetKnownFolderPath( REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PCWSTR pszPath );
A GUID that identifies the known folder.
Either 0 or the following value.
If this flag is set, portions of the path referenced by pszPath may be represented by environment strings such as
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.
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.
|Windows version||Windows Vista [desktop apps only] Windows Server 2008 [desktop apps only]|
|Header||shlobj_core.h (include Shlobj.h)|
|DLL||Shell32.dll (version 6.0.6000 or later)|