如何禁用VirtualStore for C++程序?

Zai*_*zvi 7 c++ windows file-io fopen virtualstore

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

如何禁用该虚拟商店?

谢谢

编辑:只是要明确,我不是要求如何规避安全性并在受保护的位置创建我的文件.我希望文件创建失败,这样我就可以告诉用户他是个白痴.

Jos*_*hua 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>
Run Code Online (Sandbox Code Playgroud)


Jon*_*Jon 6

来自MSDN:

虚拟化仅适用于:

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

禁用虚拟化:

  • 64位进程
  • 非交互式流程
  • 冒充的过程
  • 内核模式调用者
  • 具有requestedExecutionLevel的可执行文件

正如Adam Maras指出的那样,最好的办法是通过添加清单在应用程序上设置requestedExecutionLevel.requestOecutionLevel为"asInvoker"将导致文件操作在受保护的位置失败,而不是重定向到虚拟存储或提示提升.