System.IO.File.Exists (@ "C: \ Windows \ System32 \ SnippingTool.exe") returns false

So, I'm working on a simple .NET program to work and hit a little weird road block that I can't understand. The application uses a configuration file that adds applications to the drop-down menu. However, before adding to the menu, the system.io.file.exists file checks if the file exists, at least during menu creation.

However, System.IO.File.Exists (@ "C: \ Windows \ System32 \ SnippingTool.exe") returns false, but the executable exists. Similarly, stikynot.exe also returns false. Other files in the system32 directory return true (for example, notepad). I can register these applications, but my .net program simply cannot read them, and system.io.file.exists returns false. I checked various permissions with no luck. It seems to be isolated from several applications, but I'm not sure why.

+5
source share
2 answers

This is a feature of 64-bit Windows.

In x64, you have two folders with system files: system32 and SysWOW64 .

If you put something in system32 , this will be visible to all 64-bit applications. SysWOW64 exists for compatibility reasons - everything that fits there will be displayed by 32-bit applications (sic!).

So, with regard to .NET, the file does not exist. It works for notepad because notepad.exe is present in both of these directories.

You can check this behavior. Create a text file in one of the directories, but not in the other, and verify its existence. Then change the project configuration (right-click on the solution → Configuration Manager) between x86 and x64 and get the result.

+9
source

I have a crazy mistake related to this topic. Thanks ya23.

In my case, just change the project "Properties"> "Assembly"> "Cancel". Prefer 32-bit

+2
source

Source: https://habr.com/ru/post/949049/


All Articles