如何使用UAC获取Vista中文件的实际路径?
我正在调用 CreateFile() 在程序数据目录中创建一个文件。 我正在使用 SHGetSpecialFolderPath() 来获取目录名称。
我有一位使用 Vista 的用户,CreateFile() 返回错误 5(访问被拒绝)。 如果我知道 CreateFile() 实际上在哪里尝试创建文件,这样我们就可以检查他的文件夹权限,这将会有所帮助。 Vista (UAC) 的问题是,它不会尝试在我传入的目录中创建文件。它也可能位于 VirtualStore 目录中。 另一个令人困惑的来源是该用户是德国人,尽管 SHGetSpecialFolderPath() 返回“C:\Program Data\blah blah”作为路径,但我认为这实际上并不是路径所在的位置。 我认为德语 Vista 使用德语单词“程序数据”。 我希望能够告诉用户“这是我们尝试创建文件的确切路径。检查您对此文件夹的权限。”
我知道您可以从打开的文件句柄获取路径,但在这种情况下 CreateFile() 失败,因此我没有打开的句柄。 如何让 Vista 告诉我它尝试创建文件的实际路径?
I am calling CreateFile() to create a file in the Program Data directory. I'm using SHGetSpecialFolderPath() to get the dir name.
I have a user with Vista for whom CreateFile() is returning error 5 (Access Denied). It would help if I knew where CreateFile() was actually attempting to create the file so we can check his folder permissions. The problem with Vista (UAC) is, it's not attempting to create the file in the directory I passed in. It could also be in a VirtualStore directory. An added source of confusion is this user is German and although SHGetSpecialFolderPath() is returning "C:\Program Data\blah blah" as the path, I don't think that's actually where the path is. I think German Vista uses the German word for "Program Data". I would like to be able to tell the user "This is the exact path where we are trying to create the file. Check your permissions on this folder."
I know you can get the a path from an open file handle, but in this case the CreateFile() is failing so I don't have an open handle. How can I get Vista to tell me the actual path where it's attempting to create the file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
启动 Process Monitor 并观察它的作用:
http://technet.microsoft.com/en-us/sysinternals/bb896645。 ASPX
Fire up Process Monitor and watch what it does:
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
如果使用 UAC 时使用的路径不是您想要的路径,则重定向将生效。
要确保不会发生重定向,请添加 清单到您的应用程序,这向 Vista 表明您的应用程序已正确编码并了解访问限制(即,您不会写入 HKLM 或程序文件夹,如果您的应用程序不需要管理员权限即可运行)。
但是您的应用程序应该能够写入 APPDATA 文件夹(如果您真正使用的是该文件夹)。
确保您使用的是 CSIDL_APPDATA 而不是 CSIDL_COMMON_APPDATA(后者只能通过管理员权限访问)。
要找到真实路径(您期望的路径),请告诉用户在资源管理器栏中键入%APPDATA%(或按Windows + R,然后键入%APPDATA%,回车)。 这将打开该文件夹的资源管理器。
If with UAC the paths used are not the ones you want, then the redirection is in effect.
To make sure that redirection does not occur, add a manifest to your application which indicates to Vista that your application is properly coded and aware of access restrictions (i.e., you don't write to e.g., HKLM or the programs folder if your app doesn't need admin privileges to run).
But your application should be able to write to the APPDATA folder (if that's what you really use).
Make sure you're using CSIDL_APPDATA and not CSIDL_COMMON_APPDATA (the latter one being accessible only with admin privileges).
To find the real path (the one you would expect) tell the user to type %APPDATA% into the explorer bar (or hit Windows+R, then type %APPDATA%, enter). This will open the explorer on that folder.
我的理解是,Vista 使用 ProgramData 来写入尝试在 C:\Program Files 中写入的文件,但失败了,因为除非您以管理员身份运行该应用程序,否则您无法在程序文件中写入。 也许您应该尝试将文件保存到当前用户下的AppData文件夹中。
My understanding is that ProgramData is used by Vista to write files that were attempting to be written inside C:\Program Files, but failed, since unless you are running the app as Admin you can't write inside program files. Maybe you should try saving your files to the AppData folder under the current user.