Jump to content

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


hoanghapc
 Share

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 comment
Share on other sites

 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,
 

Link to comment
Share on other sites

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.

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

Spoiler

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

ADO - Wiki

 

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

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...