昨天刚好用到,就在以前的_DeleteSelf基础上改写一个。
;===============================================================================
; 说明: 退出后更新脚本自身
; 语法: _UpdateSelf($sFile[, $iDelay = 1[, $iResume = 0[, $sParm = ""]]])
; 参数: $sFile - 源更新文件
; $iDelay - [可选] 监视退出的间隔时间, 单位为秒
; $iResume - [可选] 更新后重新运行。0 - 不运行, 非0 - 重新运行
; $sParm - [可选] 重新运行命令行参数
; 需要: 无
; 返回: 成功 - 1
; 失败 - 0, 并设置 @error 到 1
; 备注: 无
;===============================================================================
Func _UpdateSelf($sFile, $iDelay = 1, $iResume = 0, $sParm = "")
Local $CmdFile, $CmdCont
If NOT FileExists($sFile) Then Return SetError(1, 0, 0)
$iDelay = Int($iDelay)
If $iDelay < 1 Then $iDelay = 1
$CmdCont = 'attrib -r -s -h "' & @ScriptFullPath & '"' & @CRLF _
& ':loop' & @CRLF _
& 'ping -n ' & $iDelay + 1 & ' 127.0.0.1 > nul' & @CRLF _
& 'del "' & @ScriptFullPath & '"' & @CRLF _
& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
& 'move /y "' & $sFile & '" "' & @ScriptFullPath & '"' & @CRLF
If $iResume Then
If $sParm = "" Then
$CmdCont &= '"' & @ScriptFullPath & '"' & @CRLF
Else
$CmdCont &= '"' & @ScriptFullPath & '" ' & $sParm & @CRLF
EndIf
EndIf
$CmdCont &= 'del %0' & @CRLF
$CmdFile = _TempFile(@TempDir, "~UPD", ".bat", 4)
FileWrite($CmdFile, $CmdCont)
Run($CmdFile, @TempDir, @SW_HIDE)
Return 1
EndFunc ;==>_UpdateSelf
|