Jump to content
hoanghapc

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

Recommended Posts

hoanghapc

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?

 

Share this post


Link to post
Share on other sites
VIP

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

 

C#

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);

Example:

IntPtr wow64Value = IntPtr.Zero;

// Disable redirection.
Wow64DisableWow64FsRedirection(ref wow64Value);

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

// Re-enable redirection.
Wow64RevertWow64FsRedirection(wow64Value);

 

Edited by VIP
move

Regards,
 

Share this post


Link to post
Share on other sites
caramen

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

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

image.png.0751bd89f3b531e19e0440b469df79ed.png

 

Regards,

Cara.


IUIAutomation From Junkew WebDriver From Danp2

 

Share this post


Link to post
Share on other sites
Subz

Or use EnvGet example:

Local $sProgramFiles = @OSArch = "x64" ? EnvGet("ProgramW6432") : EnvGet("ProgramFiles")
MsgBox(4096, "Program Files Dir", $sProgramFiles)

 

Share this post


Link to post
Share on other sites
Earthshine

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");
}

https://stackoverflow.com/questions/194157/c-sharp-how-to-get-program-files-x86-on-windows-64-bit


My resources are limited. You must ask the right questions

 

Share this post


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

×