UAC、VirtualStore 和 dll 互操作
我遇到了第 3 方组件的问题,我必须与 C# 或 C++ 进行互操作,但无法控制。
情况如下:
第 3 方组件是一个将数据写入“Program Files”文件夹的软件。在 Win7 中,这意味着对于没有管理员访问权限的用户,此数据将写入配置文件中的虚拟化 Program Files 文件夹中。我需要通过捆绑的 .dll 中提供的 API 读取该数据。
当使用管理员权限运行第 3 方工具并禁用 UAC 时(有效地允许对 c:\Program Files 进行写访问),我可以使用标准互操作(C++ 中的 LoadLibrary/GetProcAddress 或 C++ 中的 P/Invoke)从该文件夹读取数据C#)。需要明确的是,在这种情况下,第三方软件和我使用 .dll 的工具都从 C:\Program Files 写入/读取(使用 sysinternals 的进程监视器进行验证)。
问题是:在启用 UAC 的系统上,第 3 方软件写入虚拟化文件夹,但我的工具仍然从 C:\Program Files 读取,因此我无法读取数据。请注意,我对此无法控制,因为我无法直接读取这些数据,所以我必须通过第 3 方 .dll!所以我想我的问题是:我该怎么做才能使我的程序表现得像第 3 方组件,即在以有限的权限运行时强制它从 VirtualStore 读取?或者我应该以不同的方式处理这个问题?
I'm having an issue with a 3rd party component I have to interop with from C# or C++ but have no control over.
Here's the situation:
The 3rd party component is a piece of software that writes data to the 'Program Files' folder. In Win7, this means that for users without admin access, this data will be written in the virtualized Program Files folder in there profile. I need to read that data through an API provided in a bundled .dll.
When running the 3rd party tool with admin rights and a box with UAC disabled (effectively allowing write access to c:\Program Files), I can read the data from that folder using standard interop (LoadLibrary/GetProcAddress in C++ or P/Invoke in C#). To be clear, in this case both the 3rd party software and my tool using the .dll are writing/reading from C:\Program Files (verified with Process Monitor from sysinternals).
Here's the problem: on a system with UAC enabled, the 3rd party software writes to the virtualized folder, but my tool still reads from C:\Program Files, so I can't read the data. Please note that I have no control over this, since I can't directly read this data, I must go through the 3rd party .dll! So I guess my question is at this point: what can I do to make my program behave like the 3rd party component, i.e. force it to read from the VirtualStore when running with limited privileges? Or should I go about this differently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种情况,有两种可能的解决方案
我们选择了第二个选项,因为第 3 方工具没有提供可编写脚本的方法来更改安装文件夹:- (
There are 2 possible solutions for this scenario
We went with the second option as the 3rd party tool did not provide a scriptable way to change the installation folder :-(