7

我希望我的程序在尝试在 C:\ 驱动器的根目录(例如:)等受保护位置创建文件时抛出错误FILE* FileHandle = fopen("\\file.txt", a)。而是在 %APPDATA% 下的虚拟存储中创建文件。

如何禁用该虚拟商店?

谢谢

编辑:为了清楚起见,我不是在问如何绕过安全性并在受保护的位置创建我的文件。我希望文件创建失败,以便我可以告诉用户他是个白痴。

4

3 回答 3

17

您添加一个应用程序清单。选择 asInvoker、highestAvailable 或 requireAdministrator。听起来你想要 asInvoker。

来自http://msdn.microsoft.com/en-us/library/bb756929.aspx

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>
于 2011-01-18T23:11:44.977 回答
6

来自MSDN

虚拟化仅适用于:

  • 32 位交互进程
  • 管理员可写文件/文件夹和注册表项

虚拟化被禁用:

  • 64位进程
  • 非交互过程
  • 模拟的进程
  • 内核模式调用者
  • 具有请求执行级别的可执行文件

正如 Adam Maras 所说,您最好的选择是通过添加清单在您的应用程序上设置 requestedExecutionLevel。“asInvoker”的 requestedExecutionLevel 将导致文件操作在受保护位置上失败,而不是重定向到虚拟存储或提示提升。

于 2011-01-19T21:07:33.710 回答
3

这是一篇展示如何关闭虚拟化的文章。

http://www.interworks.com/blogs/dsmith/2011/09/21/disabling-windows-7-virtual-store

它的短处是:

- 从 Windows 7 Start Orb,搜索本地安全策略并选择它。

- 展开本地策略并单击安全选项。在右侧窗格中,一直滚动到底部,您将找到一个名为“用户帐户控制:虚拟化文件和注册表写入失败到每个用户位置”的设置,双击该设置并将其更改为已禁用。

于 2013-12-29T23:14:29.270 回答