Skip to content

Commit a83b36c

Browse files
JacobNolan1Jacob Nolan
andauthored
Perform file move of pythonservice.exe during install (#2251)
During service install perform file move of pythonservice.exe if file exists at src Co-authored-by: Jacob Nolan <[email protected]>
1 parent 377a3ef commit a83b36c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

win32/Lib/win32serviceutil.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ def LocatePythonServiceExe(exe=None):
5050
# pywin32 installed it next to win32service.pyd (but we can't run it from there)
5151
maybe = os.path.join(os.path.dirname(win32service.__file__), exe)
5252
if os.path.exists(maybe):
53-
print(f"copying host exe '{maybe}' -> '{correct}'")
54-
win32api.CopyFile(maybe, correct)
53+
print(f"moving host exe '{maybe}' -> '{correct}'")
54+
# Handle case where MoveFile() fails. Particularly if destination file
55+
# has a resource lock and can't be replaced by src file
56+
try:
57+
win32api.MoveFileEx(maybe, correct, win32con.MOVEFILE_REPLACE_EXISTING)
58+
except win32api.error as exc:
59+
print(f"Failed to move host exe '{exc}'")
5560

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

0 commit comments

Comments
 (0)