pyqt5打包程序实现更新功能
网上找了一些方法可以使用update.exe,或者使用vbs脚本。
感觉直接使用vbs脚本执行cmd更简单一点,记录一下。
vbs = r"""
Dim ws
Set ws = WScript.CreateObject("WScript.Shell")
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
src = "{}\"
dst = "{}\"
ws.Run("cmd /c taskkill /f /im main.exe "+">>test.txt")
WScript.Sleep(2000)
ws.Run("cmd /c xcopy /e /Y /s "+src+" "+dst+">>test.txt"),1,true
If fso.fileExists(dst + "main.exe") Then
ws.Run("cmd /c"+dst + "main.exe"),1,true
End If
"""
vbs_script = vbs.format(download_path, install_path)
with open('update.vbs', 'w', encoding='utf-8') as f:
f.write(vbs_script)
import subprocess
subprocess.call("cscript update.vbs", creationflags=0x08000000)