原文
SHGetKnownFolderPath
通过一个 KNOWNFOLDERID
标志获取对应已知文件夹的完整路径。
Retrieves the full path of a known folder identified by the folder’s KNOWNFOLDERID.
函数原型
HRESULT SHGetKnownFolderPath(
REFKNOWNFOLDERID rfid,
DWORD dwFlags,
HANDLE hToken,
PWSTR *ppszPath
);
参数
rfid
类型:REFKNOWNFOLDERID
一个用于标志文件夹的常值引用。
A reference to the KNOWNFOLDERID that identifies the folder.
dwFlags
类型:DWORD
用于指定特殊选项的标记。其值可以为 0
;或者为枚举类型 KNOWN_FOLDER_FLAG
中的一个或多个。
Flags that specify special retrieval options. This value can be 0; otherwise, one or more of the KNOWN_FOLDER_FLAG values.
hToken
类型:HANDLE
代表特定用户的访问令牌(access token)。如果这个参数是 NULL
(一般都是),该函数将获取当前用户的对应文件夹。
An access token that represents a particular user. If this parameter is NULL, which is the most common usage, the function requests the known folder for the current user.
要获取某一特定用户的文件夹,需要传入那个用户的 hToken
。通常要做到这一点要求要在有足够权限获取文件夹路径的服务的上下文中完成。该令牌必须有 TOKEN_QUERY
和 TOKEN_IMPERSONATE
权限。某些情况下,你还需要有 TOKEN_DUPLICATE
权限。除了要传入 hToken
,……
Request a specific user’s folder by passing the hToken of that user. This is typically done in the context of a service that has sufficient privileges to retrieve the token of a given user. That token must be opened with TOKEN_QUERY and TOKEN_IMPERSONATE rights. In some cases, you also need to include TOKEN_DUPLICATE. In addition to passing the user’s hToken, the registry hive of that specific user must be mounted. See Access Control for further discussion of access control issues.
给 hToken
赋 -1
表示默认用户(Default User)。这将获取默认用户的路径。当新用户创建时,默认用户的所有内容将被复制。注意访问默认用户文件夹需要管理员权限。
Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHGetKnownFolderPath to find 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.
ppszPath
类型:PWSTR*
当该函数返回后,该参数指向的指针将指向一个记录着指定文件夹完整路径的以 0 结尾的 Unicode 字符串。当这个被指向的字符串不再被需要时,调用这个函数的进程需要负责释放这个指针的资源,方法是调用 CoTaskMemFree
。获得的路径在最后不包含反斜线。例如,返回的不会是 C:\Users\
,只会是 C:\Users
。
When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the path of the known folder. The calling process is responsible for freeing this resource once it is no longer needed by calling CoTaskMemFree. The returned path does not include a trailing backslash. For example, “C:\Users” is returned rather than “C:\Users”.
返回值
类型:HRESULT
如果成功,返回 S_OK
。否则返回下列错误代码:
E_FAIL
这个值可以代表 rfid
参数对应的文件夹没有路径(比如用 KF_CATEGORY_VIRTUAL
标记的路径)
Among other things, this value can indicate that the rfid parameter references a KNOWNFOLDERID which does not have a path (such as a folder marked as KF_CATEGORY_VIRTUAL).
E_INVALIDARG
这个值可以代表 rfid
参数对应的文件夹在系统中不存在。并不是所有的 KNOWNFOLDERID
在任何系统上都存在。用 IKnownFolderManager::GetFolderIds
获取当前系统存在的文件夹的 KNOWNFOLDERID
。
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.
备注
这个函数取代了 SHGetFolderPath
。现在那个老函数只是 SHGetKnownFolderPath
的一个封装。
This function replaces SHGetFolderPath. That older function is now simply a wrapper for SHGetKnownFolderPath.
需求
……(见原文)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)