如何(以编程方式)获取Windows UAC虚拟文件的位置? [英] How to get (programatically) the location of a Windows UAC virtualized file?

查看:108
本文介绍了如何(以编程方式)获取Windows UAC虚拟文件的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个32位Windows旧应用程序(带有C/Win32源代码),该应用程序在可执行文件所在的文件夹中创建其数据文件.

I have a 32-bit windows old application (with the C/Win32 source) that creates its data file in the same folder where the executable is.

由于该应用程序没有安装程序,并且用户可以将可执行文件放置在他/她想要的任何位置,因此该应用程序具有一个对话框,通知用户其数据位于何处.

Because the application has no installation program and the user can place the executable wherever he/she wants, the application has a dialog to inform the user where its data is located.

但是在Microsoft Vista/Seventh下,即使用户将应用程序放在程序文件"或任何其他受系统保护的文件夹中,数据文件也会被虚拟化并移动到虚拟存储中.

But under Microsoft Vista/Seven if the user puts the application in the Program Files or any other system-protected folder the data file gets virtualized and moved to a virtual-store.

如果在Vista/Seven下,我仍然想通知用户数据文件的位置: (不阻止清单文件中的虚拟化)

If, under Vista/Seven, I still want to inform the user where the data file is located: (without preventing virtualization in the manifest file)

  1. 如何(以编程方式)知道数据文件是否已虚拟化?还是如果可执行文件所在的文件夹暗示数据文件将被虚拟化?

  1. How can I know (programatically) if the data file is virtualized? Or if the folder where the executable is located implies that data file will be virtualized?

假设我知道数据文件已虚拟化,如何(以编程方式)知道虚拟文件夹的位置,以在信息对话框中显示它?

Assuming I know the data file is virtualized, how can I know (programatically) the location of the virtual folder, to show it in the information dialog?

我发现以下问题与我的要求非常接近,但是它没有提供知道何时对文件进行虚拟化以及将其虚拟化的解决方案(如果有).

I have found the following question very close to what I'm asking but it doesn't show the solution (if any) of knowing when virtualization is taking place for a file, and where it gets virtualized.

如何检测文件重定向到Windows VirtualStore?

推荐答案

虚拟化对应用程序是透明的.知道它是否正在虚拟化的唯一方法是根据链接到的问题的答案询问操作系统(使用带有TokenVirtualizationEnabled标志的GetTokenInformation()),但是没有办法(我知道)向OS询问虚拟化项目的实际存储位置,因为它可能与一个OS版本不同.您将需要做一些研究,然后硬编码您的应用在运行时检测到的每个给定OS的路径.

Virtualization is transparent to the app. The only way to know whether it is being virtualized is to ask the OS, per the answer in the question you linked to (use GetTokenInformation() with the TokenVirtualizationEnabled flag), but there is no way (that I know of) of asking the OS where the virtualized items are actually stored, as it may be different from one OS version to the next. You will have to do some research and then hard-code the paths for each given OS that your app detects at runtime.

如果您要更新代码以检测虚拟化,那么最好更新代码,以使其与UAC更好地兼容.停止将文件存储在不属于它们的位置,并开始将它们存储在Microsoft希望您存储它们的位置.在这种情况下,请改为在用户的个人资料中.使用SHGetFolderPath()或相关功能找到用户的CSIDL_LOCAL_APPDATA文件夹(或在Vista +上的SHGetKnownFolderPath()来找到FOLDERID_LocalAppData文件夹),然后在其下创建一个子文件夹,以供您的应用存储其数据文件.

If you are going to update your code to detect virtualization, then you are better off updating the code to play nicer with UAC instead. Stop storing your files where they do not belong, and start storing them where Microsoft wants you to store them. In this case, within the user's profile instead. Use SHGetFolderPath() or related function to locate the user's CSIDL_LOCAL_APPDATA folder (or SHGetKnownFolderPath() on Vista+ to locate the FOLDERID_LocalAppData folder), then create a subfolder underneath it for your app to store its data files in.

这篇关于如何(以编程方式)获取Windows UAC虚拟文件的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆