Python cant see files or folders in C:\Windows\System32\GroupPolicy -


i'm running problem python unable see folders or files exist on computer. have ensured path has no symbolic links in , have full control on ntfs file permissions. have removed hidden attributes. below script using , output:

import os path = 'c:\\windows\\system32\\grouppolicy\\machine' print path test = os.path.exists(path) print test  c:\windows\system32\grouppolicy\machine false 

i unsure why returning false when have ensured folder exist. if remove "\machine" path, returns true. have verified following command works command prompt:

if exist c:\windows\system32\grouppolicy\machine echo found 

any advice on how working in python appreciated. here version of python using: python 2.7.6 (default, nov 10 2013, 19:24:18) [msc v.1500 32 bit (intel)] on win32

alright, after digging, found nothing permissions has file system redirection. using x86 version of python on windows x64 (using x86 using py2exe), windows redirecting queries on system32 , subdirectories syswow64. means querying "c:\windows\syswow64\grouppolicy\machine" did not exist.

to fix this, found how disable file system redirection using recipe found here: http://code.activestate.com/recipes/578035-disable-file-system-redirector/

here final code works disable redirection , allows opening , querying of files in system32 on 64 bit machine.

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)   disable_file_system_redirection().__enter__() import os path = 'c:\\windows\\system32\\grouppolicy\\machine' print path test = os.path.exists(path) print test 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -