How to detect file redirection to the Windows VirtualStore?

前端 未结 3 1314
旧时难觅i
旧时难觅i 2020-12-05 15:42

Since the release of Win Vista, Microsoft introduced file virtualization for legacy applications running as 32bit processes. Released as part of Microsoft\'s User Account Co

3条回答
  •  眼角桃花
    2020-12-05 16:42

    FWIW, here is a version of the detection code in Delphi:

    unit checkvirtual;
    
    interface
    uses windows;
    
    function GetVirtualizationEnabled(var enabled:Boolean):Boolean;
    
    implementation
    
    // Gets whether the current process has UAC virtualization enabled.
    // Returns TRUE on success and FALSE on failure.
    function GetVirtualizationEnabled(var enabled:Boolean):Boolean;
    var
      token:THandle;
      tmpEnabled:DWORD;
      returnLen:DWORD;
    begin
      result:=false;
      enabled:=false;
      if not(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token)) then exit;
      try
        if not(GetTokenInformation(token, TokenVirtualizationEnabled,
                  @tmpEnabled, sizeof(tmpEnabled), returnLen)) then exit;
    
        enabled:=tmpEnabled<>0;
        result:=true;
      finally
        CloseHandle(token);
      end;
    end;
    
    end.
    

提交回复
热议问题