#NoTrayIcon
#RequireAdmin
#Region
#PRE_Icon=..\..\..\远控客户端.exe
#PRE_Outfile=..\..\..\远控客户端.exe
#PRE_UseX64=n
#PRE_Res_Description=TODESK
#PRE_Res_Fileversion=1.0.0.1
#PRE_Res_LegalCopyright=i@smallan.net
#PRE_Res_requestedExecutionLevel=None
#EndRegion
;https://newdl.todesk.com/windows/ToDesk_Lite.exe
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <WindowsConstants.au3>
HotKeySet('{esc}', '_Exit')
Run(@ComSpec & " /c " & 'NET STOP ToDesk_Service', "", @SW_HIDE)
Run(@ComSpec & " /c " & 'taskkill /f /im ToDesk_Lite.exe', "", @SW_HIDE)
Local $Gui, $iLb, $label, $prgCurrent, $lblCurrent, $DummyMenu, $ContextMenu, $hMenu, $ExitMenuItem, $CurInfo
Local $SaveFile = @TempDir & "\ToDesk_Lite.exe"
Local $DownloadFile = "https://newdl.todesk.com/windows/ToDesk_Lite.exe"
_OpenUpdateWindow($SaveFile, $DownloadFile)
#Region 创建下载窗口
Func _OpenUpdateWindow($SaveFile, $DownloadFile)
If StringLen($SaveFile) <= 0 Or StringLen($DownloadFile) <= 0 Then Return
$Gui = GUICreate('软件更新', 311, 121, -1, -1, 0x80000000, 0x00000008)
$iLb = GUICtrlCreateLabel('', 0, 0, 311, 121, -1, 0x00100000)
$label = GUICtrlCreateLabel('ToDesk更新中,稍后自动运行', 24, 24, 264, 30, -1, 0x00100000)
GUICtrlSetFont(-1, 14, 800, 0, "微软雅黑")
$prgCurrent = GUICtrlCreateProgress(24, 64, 240, 25)
$lblCurrent = GUICtrlCreateLabel("0%", 265, 70, 20, 15, $SS_RIGHT)
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$hMenu = GUICtrlGetHandle(-1)
$ExitMenuItem = GUICtrlCreateMenuItem('Exit', $ContextMenu)
GUISetState(@SW_SHOW)
While 1
_Download($SaveFile, $DownloadFile)
$CurInfo = GUIGetCursorInfo($Gui)
If Not @error And ($CurInfo[3] = 1 And ($CurInfo[4] = $iLb Or $CurInfo[4] = $label _
Or $CurInfo[4] = $prgCurrent Or $CurInfo[4] = $lblCurrent)) Then
_ShowMenu($Gui, $hMenu)
If GUIGetMsg() = -3 Or GUIGetMsg() = $ExitMenuItem Then _Exit()
WEnd
EndFunc ;==>_OpenUpdateWindow
#EndRegion 创建下载窗口
#Region 显示右键菜单
Func _ShowMenu($hWnd, $hMenu)
Local $arPos = MouseGetPos()
Local $X = $arPos[0]
Local $Y = $arPos[1]
DllCall('user32.dll', 'int', 'TrackPopupMenuEx', 'hwnd', $hMenu, 'int', 0, 'int', $X, 'int', $Y, 'hwnd', $hWnd, 'ptr', 0)
EndFunc ;==>_ShowMenu
#EndRegion 显示右键菜单
#Region 下载文件
Func _Download($SaveFile = '', $DownloadFile = '')
Local $hDownload = InetGet($DownloadFile, $SaveFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
Local $aData = InetGetInfo($hDownload)
Local $currPercent = ($aData[$INET_DOWNLOADREAD] / $aData[$INET_DOWNLOADSIZE]) * 100
GUICtrlSetData($prgCurrent, $currPercent)
GUICtrlSetData($lblCurrent, Floor($currPercent) & "%")
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
InetClose($hDownload)
Run(@ComSpec & " /c " & $SaveFile, "", @SW_HIDE)
_Exit()
EndFunc ;==>_Download
Func _Exit()
Exit
EndFunc ;==>_Exit
自动下载软件并运行,显示进度条