Yes, virtualization happens at a very low level. The File.Exists method basically calls the Win32 CreateFile method and checks for errors. CreateFile is redirected by the WOW subsystem.
You can disable virtualization temporarily before calling.
[DllImport( "kernel32", CharSet=CharSet.Unicode, SetLastError=true )]
public static extern bool Wow64DisableWow64FsRedirection( ref IntPtr oldValue );
[DllImport( "kernel32", CharSet=CharSet.Unicode, SetLastError=true )]
public static extern bool Wow64RevertWow64FsRedirection( IntPtr oldValue );
Of course to be complete you'll have to check for file existence with virtualization on as well as off. The same applies for checking registry entries as well.
public static bool FileExists( string path )
{
if( File.Exists( path ) ) return true;
IntPtr oldValue = IntPtr.Zero;
try
{
if( Environment.GetEnvironmentVariable( "PROCESSOR_ARCHITEW6432" ) == null )
return false;
Wow64DisableWow64FsRedirection( ref oldValue );
if( File.Exists( path ) ) return true;
return false;
}
finally
{
if( oldValue != IntPtr.Zero )
Wow64RevertWow64FsRedirection( ref oldValue );
}
}
Update: You may also need to check the OS version before disabling the WOW redirection because earlier versions of XP (Pre SP2 I believe) do not expose those methods.
Update 2: Added OS check for 64-bit. All 64-bit versions of the OS implement these methods and you only need to disable the sate if running on a 64-bit OS.