Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonservice.exe is not longPathAware #2455

Open
moorec-aws opened this issue Jan 8, 2025 · 0 comments
Open

pythonservice.exe is not longPathAware #2455

moorec-aws opened this issue Jan 8, 2025 · 0 comments

Comments

@moorec-aws
Copy link

moorec-aws commented Jan 8, 2025

Description

By default Python is long path aware. We recently discovered when running our application via a service using pywin32 that our application could not access long paths even tho long path support was enabled on the host. We discovered that pythoservice.exe was not long path aware. We found that we were able to add long path support manually by using an application manifest and the Windows SDK mt.exe tool.

This issue is for making pythonservice.exe longPathAware when it is built so that a workaround does not have to be performed.

Expected behavior and actual behavior

Expected:

  • Service scripts running through pythonservice.exe are long path aware when the hosts registry has long paths enabled.

Actual:

  • Service scripts running through pythonservice.exe not long path aware when the hosts registry has long paths enabled.

Steps to reproduce the problem

  1. Enable Long Paths Registry Key

  2. Download and Unzip: LongPathTest.zip

  3. Install the Service:

pip install pywin32
python service_test.py install
pywin32_postinstall.py -install
  1. Start the TESTING Service Windows service.
  2. Check the service-test-log.txt log in LongPathTest directory. There will be a [Errno 2] No such file or directory error.

Updating pythonservice.exe to be longPathAware:

  1. Install Windows SDK using the installer.
    • Specifically install Windows SDK for Desktop C++ x86 Apps
  2. Go to the python installation location of your environment where the Worker Agent is installed (Default: C:\Program Files\Python311), there should be an executable there called pythonservice.exe
  3. Create a new file called pythonservice.exe.manifest in the same location and add the following contents:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="pythonservice" processorArchitecture="x86" version="1.0.0.0"/>
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
  </application>
</assembly>
  1. Run the following command using command prompt with the path to pythonservice.exe.manifest :
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x86\mt.exe" -manifest "C:\Program Files\Python311\pythonservice.exe.manifest" -outputresource:"C:\Program Files\Python311\pythonservice.exe";#1
  1. Expected return value:
Microsoft (R) Manifest Tool
Copyright (c) Microsoft Corporation.
All rights reserved.
  1. Start the TESTING Service Windows service.
  2. Check the service-test-log.txt log in LongPathTest directory and you should see that the long path was read.
2025-01-08 16:38:58,741 [INFO   ] Attempting to Access Long Path
2025-01-08 16:38:58,741 [INFO   ] Long Paths Working!!

System information

Python version and distribution: 3.11.11

pywin32 version: 308

Windows Version: 10.0.19045 Build 19045

DLL locations:

C:\Program Files\Python311\pywintypes311.dll
C:\Program Files\Python311\Lib\site-packages\pywin32_system32\pythoncom311.dll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant