Questions about python2.7 some windows systems, the path appeared to open an existing file or directory report does not exist

problem

Writer at work, need access, C: \\ Windows \\ System32 \\ winevt \\ files under. I use a python open function. This title says there have been problems. Test code is as follows:

fn = "C:\Windows\System32\winevt\Logs\Security.evtx"

fo = open(fn,"r")

After this problem, I first thought the permissions, but I try to run this code with administrator privileges, the problem still exists. What puzzles the landlord tried separately c, java language in which the existence of such problems c language.

As a writer even more puzzled! Fortunately I saw this question https://q.cnblogs.com/q/82369/ .

the reason

32 runs in 64-bit windows system, if folder redirection is not disabled, then the C: \\ Windows \\ System32 \\, C: \ Program Files access will be redirected to a different location. This process is done by the operating system.

Solution:

C language calling Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection disable or redirect restore files in the calling thread. Note that disabling or restore file redirection affects only the calling thread, other threads or processes are not affected

python code as follows

import ctypes
kernel32 = ctypes.windll.LoadLibrary("kernel32.dll")
carg = ctypes.c_voidp(None)
kernel32.Wow64DisableWow64FsRedirection (CArG) # before the file operation disable file redirection 
# open files and file operations 
kernel32.Wow64RevertWow64FsRedirection (CArG) # before recovery set after use

 

Guess you like

Origin www.cnblogs.com/codeyi/p/11479400.html