hoanghapc Posted November 9, 2018 Posted November 9, 2018 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?
Trong Posted November 9, 2018 Posted November 9, 2018 (edited) 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 November 9, 2018 by VIP move Regards,
caramen Posted November 9, 2018 Posted November 9, 2018 I guess you can manage all path with all language with this key : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion 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 - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Subz Posted November 9, 2018 Posted November 9, 2018 Or use EnvGet example: Local $sProgramFiles = @OSArch = "x64" ? EnvGet("ProgramW6432") : EnvGet("ProgramFiles") MsgBox(4096, "Program Files Dir", $sProgramFiles)
Earthshine Posted November 9, 2018 Posted November 9, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now