[issue41862] can not open file in system folder

2020-09-25 Thread Eryk Sun


Eryk Sun  added the comment:

> 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".

--
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41862] can not open file in system folder

2020-09-25 Thread Christopher Reilly


New submission from Christopher Reilly :

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.dllLoaded
> 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 
> 
> 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?

--
components: IO, Installation, Windows, ctypes
messages: 377489
nosy: paul.moore, reilly.christopher, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: can not open file in system folder
type: behavior
versions: Python 3.8

___
Python tracker