This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: can not open file in system folder
Type: behavior Stage: resolved
Components: ctypes, Installation, IO, Windows Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, paul.moore, reilly.christopher, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-09-25 12:48 by reilly.christopher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg377489 - (view) Author: Christopher Reilly (reilly.christopher) Date: 2020-09-25 12:48
I am trying to load a Windows dll "ibfs64.dll" located in the C:\Windows\System32 folder:

    ctypes.windll.LoadLibrary('ibfs64.dll')

When I attempt this call with Python 3.8.5 downloaded from python.org, the call fails with 

> FileNotFoundError: Could not find module 'ibfs64.dll' (or one of its dependencies). Try using the full path with constructor syntax.

The function call, however, succeeds in Python 3.7.9 (downloaded from python.org). This behavior (3.7.9 works, 3.8.5 does not), has been duplicated by another user on two different Windows 10 machines (my machine is also Windows 10).

Another piece of information is that this function call also succeeds in anaconda environments running Python 3.7.9 and Python 3.8.5.

When I use the dll-diagnostics tracing utility (https://pypi.org/project/dll-diagnostics/) with the anaconda-managed Python 3.8.5 installation, it succeeds:

> DLL Diagnostic Tools version 0.0.3
> Copyright (c) 2019 Adam Rehn
> 
> Parsing module header and detecting architecture... done.
> 
> Identifying the module's delay-loaded dependencies... done.
> 
> Parsed module details: Module:          C:\Windows\System32\ibfs64.dll
> Type:            Dynamic-Link Library Architecture:    x64
> 
> The module imports 0 delay-loaded dependencies:
> 
> 
> Performing LoadLibrary() trace for C:\Windows\System32\ibfs64.dll...
> Done.
> 
> Summary of LdrLoadDll calls: C:\Windows\System32\ibfs64.dll    Loaded
> successfully
> 
> Summary of LdrpLoadDllInternal calls: C:\Windows\System32\ibfs64.dll  
> Loaded successfully NTDLL.DLL                         Loaded
> successfully
> 
> Summary of LdrpMinimalMapModule calls:
> C:\Windows\System32\ADVAPI32.dll                                      
> Mapped successfully C:\Windows\System32\ibfs64.dll                    
> Mapped successfully C:\Windows\System32\msvcrt.dll                    
> Mapped successfully C:\Windows\System32\RPCRT4.dll                    
> Mapped successfully C:\Windows\System32\sechost.dll                   
> Mapped successfully
> C:\Windows\WinSxS\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.9672_none_88e266cb2fac7c0d\MSVCR80.dll
> Mapped successfully
> 
> Summary of LdrpResolveDllName calls: ibfs64.dll    
> C:\Windows\System32\ibfs64.dll MSVCR80.dll   
> C:\Windows\WinSxS\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.9672_none_88e266cb2fac7c0d\MSVCR80.dll

But when I try it with the Python 3.8.5 installed from python.org, it fails:

> DLL Diagnostic Tools version 0.0.3
> Copyright (c) 2019 Adam Rehn
> 
> Parsing module header and detecting architecture... Traceback (most recent call last):
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
> 
> return _run_code(code, main_globals, None,
> 		       
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
> 
> exec(code, run_globals)
> 
> File "C:\Users\Chris\AppData\Local\Programs\Python\Python38-32\Scripts\dlldiag.exe\__main__.py", line 7, in <module>
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\site-packages\dlldiag\main.py", line 29, in main
> 
> subcommands[subcommand]['function']()
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\site-packages\dlldiag\subcommands\trace.py", line 188, in trace
> 
> header = ModuleHeader(args.module)
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\site-packages\dlldiag\common\ModuleHeader.py", line 14, in __init__
> 
> self._pe = pefile.PE(module, fast_load=True)
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\site-packages\pefile.py", line 1754, in __init__
> 
> self.__parse__(name, data, fast_load)
> 
> File "c:\users\chris\appdata\local\programs\python\python38-32\lib\site-packages\pefile.py", line 1797, in __parse__
> 
> stat = os.stat(fname)
> 
> FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Windows\\system32\\ibfs64.dll'

In fact, I can not even open the file in the python.org installation of Python 3.8.5, while I can in the python.org installation of Python 3.7.9. In other words, the command

    open(r'C:\Windows\System32\ibfs64.dll','r')

succeeds with the python.org installation of Python 3.7.9, but fails (same FileNotFoundError) with version Python 3.8.5. 

What is the anaconda-managed installation doing differently? Why is the Python 3.7.9 installation from python.org successful while the 3.8.5 installation is not?
msg377491 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-09-25 13:32
> File "c:\users\chris\appdata\local\programs\python\python38-32
> \lib\runpy.py", line 194, in _run_module_as_main

You have to use 64-bit Python in order to load a 64-bit DLL from the native "%SystemRoot%\System32" directory. The fact that the installation directory is "python38-32" implies that you're running 32-bit Python. In 64-bit Windows, a 32-bit program executes as a WOW64 process, for which "%SystemRoot%\System32" gets redirected to "%SystemRoot%\SysWOW64".
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86028
2020-09-25 13:32:44eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg377491

resolution: not a bug
stage: resolved
2020-09-25 12:48:03reilly.christophercreate