How do I get the 64 bit system folder in a 32 bit application?

In a 32 bit application, I need to copy the file to the 64 bit system folder
( C:\Windows\System32\

instead of C:\Windows\SysWOW64\

)

For this, I tried to get the folder using WinAPI function SHGetKnownFolderPath

with FOLDERID_ProgramFilesX64 parameter (GUID: 6D809377-6AF0-444b-8957-A3773F02200E).

But unfortunately this is not valid (as mentioned in the remarks section) and the function result is "file not found".

Is there a way to do this?

+3


source to share


2 answers


You are asking for the PROGRAM FILES folder , not the SYSTEM folder . Look FOLDERID_System

and FOLDERID_SystemX86

.

Alternatively use FOLDERID_Windows

to get the Windows installation folder and then add a custom alias SysNative

to the end, let the file redirector find the actual folder for you, per documentation :



32-bit applications can access the system directory by replacing % windir% \ Sysnative with% windir% \ System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect access. This mechanism is flexible and easy to use, so it is recommended to use file system bypass redirection. Please note that 64-bit applications cannot use the Sysnative alias, as this is a virtual directory that is not real.

+3


source


I'm confused as to why you try FOLDERID_ProgramFilesX64

when you say you want the System32 folder, since the first one (if it works) will give you the Program Files folder . For the System32 folder you want GetSystemDirectory

.

You can use the function Wow64DisableWow64FsRedirection

to disable WOW64 redirection, which allows your 32 bit application to actually access the 64 bit system folder. Then use Wow64RevertWow64FsRedirection

to restore the redirect after you're done.



Also note that it is actually not advisable to store your files in the System folder anymore (and hasn't been for a long enough time) as this note in the docs for GetSystemDirectory

says:

Applications should not create files in the system directory. If the user is running a common version of the operating system, the application is not allowed to write to the system directory.

+2


source







All Articles