Skip to content

Commit

Permalink
During service install perform file move of pythonservice.exe if file…
Browse files Browse the repository at this point in the history
… exists at src

During install perform move of pythonservice.exe instead of file copy to handle .exe always being present in src location. 

Additional try-except added to handle continuation of program if fileMove fails.
  • Loading branch information
JacobNolan1 authored Apr 29, 2024
1 parent dde12b8 commit ea5ef22
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions win32/Lib/win32serviceutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ def LocatePythonServiceExe(exe=None):
# pywin32 installed it next to win32service.pyd (but we can't run it from there)
maybe = os.path.join(os.path.dirname(win32service.__file__), exe)
if os.path.exists(maybe):
print(f"copying host exe '{maybe}' -> '{correct}'")
win32api.CopyFile(maybe, correct)
print(f"moving host exe '{maybe}' -> '{correct}'")
# Handle case where MoveFile() fails. Particularly if destination file
# has a resource lock and can't be replaced by src file
try:
win32api.MoveFile(maybe, correct)
except win32api.error as exc:
print(f"Failed to move host exe '{exc}'")


if not os.path.exists(correct):
raise error(f"Can't find '{correct}'")
Expand Down

0 comments on commit ea5ef22

Please sign in to comment.