2

I'm trying to search for a file that may be in either the "Program Files" or "Program Files (x86)" directory. However, i can't find a way to access the 64bit program files.

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)returns the x86 version. A quick google search has many people having this conflict, with people getting varied results using it.

Why am I getting the x86 folder, and how to counter it?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Michael Parr
  • 134
  • 3
  • 14
  • 1
    The point of the file system redirector is that you *can't* get to this directory. You could pinvoke Wow64DisableWow64FsRedirection to turn that off, this is however fairly dangerous in a managed app since it tends to load DLLs dynamically. Switching your EXE target to AnyCPU is the simple workaround. – Hans Passant Apr 13 '13 at 13:46
  • 2
    Thats what i had attempted, though i had forgot to uncheck "Prefer 32-bit" – Michael Parr Apr 13 '13 at 13:57

1 Answers1

-1

Probably you run your app as 32 bit Look at this dicussion to get code which returns corectlly x86 program files dir: C# - How to get Program Files (x86) on Windows 64 bit

Community
  • 1
  • 1
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116