Welcome, guest | Sign In | My Account | Store | Cart

This disables the Windows File System Redirector.

When a 32 bit program runs on a 64 bit operating system the paths to C:/Windows/System32 automatically get redirected to the 32 bit version (C:/Windows/SysWow64), if you really do need to access the contents of System32, you need to disable the file system redirector first.

Python, 22 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import ctypes

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)


#Example usage
import os

path = 'C:\\Windows\\System32\\msg.exe'

print os.path.exists(path)
with disable_file_system_redirection():
    print os.path.exists(path)
print os.path.exists(path)

1 comment

Tra Quang Kieu 6 years, 10 months ago  # | flag

Hi zxw,

I would like to say thank you very much. Your post solve my problem (cannot call 64bit commands in subprocess).

Thanks again!

Created by zxw on Mon, 6 Feb 2012 (MIT)
Python recipes (4591)
zxw's recipes (1)

Required Modules

Other Information and Tasks