Jump to content

ow to get 64-bit “program files” directory in 32-bit Application

Recommended Posts

I have an application compiled in x86 mode (in c#) from which I need to access a certain file that exists in the 64-bit program files folder (of a 64-bit Windows of course). I don't want to just hardcode C:\Program Files as a string in my application because a few target computers may have Windows installed in a different drive, or may be in another languages.

The problem I'm encountering is that using Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) returns the x86 flavor instead of the desired directory, unless I compile my program in 64-bit mode. Out of curiosity, what can I do to avoid doing such?

Link to post
Share on other sites

 For AutoIt see document: https://www.autoitscript.com/autoit3/docs/intro/64-bit_support.htm



There are Win32 functions available that can disable and enable redirection.

[DllImport("kernel32.dll", SetLastError = true)] 

static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr); 

[DllImport("kernel32.dll", SetLastError = true)] 

static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);


IntPtr wow64Value = IntPtr.Zero;

// Disable redirection.
Wow64DisableWow64FsRedirection(ref wow64Value);

// Do whatever you need
// .....................

// Re-enable redirection.


Edited by VIP


Link to post
Share on other sites

I guess you can manage all path with all language with this key :






My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote


 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

ADO - Wiki


Link to post
Share on other sites

honestly, you should google and use StackOverflow

static string ProgramFilesx86()
    if( 8 == IntPtr.Size 
        || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
        return Environment.GetEnvironmentVariable("ProgramFiles(x86)");

    return Environment.GetEnvironmentVariable("ProgramFiles");


My resources are limited. You must ask the right questions


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...