人较笨且记性不好,故记录在此.折叠代码打不开请F5.本博中很多是转载收录其他网友的文章(原文地址请见博文末尾),所有权为原作者所有!!!
此博客已不再更新和维护,欢迎关注我的github新博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

  今天在写一个测试程序的时候,使用SHGetFolderPath获取用户数据目录,在本机运行时能成功,但是放进虚拟机测试的却返回错误代码5,拒绝访问。

  同样是win7 32位。本机的UAC是最低,测试机的UAC是默认的。当时稍微查阅资料大概说是权限问题,于是将测试机的UAC设置为最低,这时程序能正常运行,但是返回的路径却不是我要的“C:\Users\Admin\AppData\Roaming”,而是一个"c:\windows\"下面的路径,很是纳闷。

  后来想到既然不能用api函数直接获取,那么可以从注册表中读取。相关注册表值见“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”。

 

Return Value 请注意

Returns standard HRESULT codes, including the following:

S_FALSE SHGetFolderPathA only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_FAIL SHGetFolderPathW only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_INVALIDARG The CSIDL in nFolder is not valid.

  扩展资料:使用SHGetFolderPath 获取系统文件夹路径

【参考资料 感谢作者】
1、 使用SHGetFolderPath 获取系统文件夹路径

posted on 2012-03-19 22:57  子坞  阅读(3090)  评论(1编辑  收藏  举报