Greatemperor 2020-06-10
#!/usr/bin/env python
# encoding: utf-8
import ctypes
import os
class disable_file_system_redirection:
"""
关闭64位系统的driver目录重定向
"""
try:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
except Exception as e:
print(str(e))
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)
with disable_file_system_redirection():
if os.path.exists(r‘C:\Windows\System32\drivers\test.sys‘):
print "yes"