OpenFileDialog showing different files depending on if build for 32-bit or 64-bit architecture [closed]

StackOverflow https://stackoverflow.com/questions/18421417

  •  26-06-2022
  •  | 
  •  

質問

I have noticed OpenFileDialog failing to show all files in a directory, this happens in my application but also other windows native programs such as Task Manager "New Task" "Browse" option (which uses the OpenFileDialog Control), does anyone know the reason and possible workarounds for that?
Even running Task Manager as admin didn't fix it so its not caused by privileges it seems

Edit: i now know this was caused by a appcompat feature called File System Redirector apparently i was starting Task Manager 32bit, aswell as my own application and hence it was showing me the 32bit system32 aka SysWOW64 folder (talk about wierd naming schemes, on Windows 7 64bit System32 has the 64bit files and SysWOW64 holds the 32bit files) and it seems that when you are running a 32bit build of a certain application you have no access to the 64bit System32 folder via OpenFileDialog whatsoever.

As example, seen here, its missing SnippingTool.exe (but its not just limited to)

TaskManager OpenFileDialog While i am certain it does exist at the target location
Windows Explorer

役に立ちましたか?

解決

This happens when you run your code on the 64-bit version of Windows. The navigation bar says that you are looking at c:\windows\system32. But you actually see the content of c:\windows\syswow64. The same thing happens when you navigate to c:\program files. You'll actually see the content of c:\program files (x86). There is no 32-bit version of SnippingTool.exe so it is missing from the list.

This is an appcompat feature called "File system redirection". Designed to give 32-bit programs a fighting chance to survive on a 64-bit operating system.

You turn it off by allowing your program to run as a 64-bit process. Right-click your EXE project, Properties, Build tab. Change the Platform target setting to AnyCPU. On VS2012 and up, untick the "Prefer 32-bit" option.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top