Registers the active instance of an application for restart.
#Include <WinAPIEx.au3>
_WinAPI_RegisterApplicationRestart ( [$iFlags [, $sCmd]] )
$iFlags | [可选参数] The flags that specifies an events when application will not be restarted. This parameter can be 0 or one or more of the following values. $RESTART_NO_CRASH $RESTART_NO_HANG $RESTART_NO_PATCH $RESTART_NO_REBOOT |
$sCmd | [可选参数] The command-line arguments for the application when it is restarted. The maximum size of the command line that you can specify is 2048 characters. If this parameter is empty string, the previously registered command line is removed. |
成功: | 返回 1. |
失败: | 返回 0 并设置 @error 标志为非 0 值, @extended 标志可能包含一个系统错误代码. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
If _WinAPI_GetVersion() < '6.0' Then
MsgBox(16, 'Error', 'Require Windows Vista or later.')
Exit
EndIf
Global $hForm, $Label, $Count = 60
$hForm = GUICreate('MyGUI', 300, 100)
$Label = GUICtrlCreateLabel('The application will be crashes after 60 seconds.', 10, 43, 280, 14, $SS_CENTER)
GUISetState()
If ($CmdLine[0]) And ($CmdLine[1] = '/crash') Then
MsgBox(48, 'Attention', 'The application has been restarted after an abnormal exit.', 0, $hForm)
EndIf
If Not @compiled Then
_WinAPI_RegisterApplicationRestart(BitOR($RESTART_NO_PATCH, $RESTART_NO_REBOOT), '"' & @ScriptFullPath & '" /crash')
Else
_WinAPI_RegisterApplicationRestart(BitOR($RESTART_NO_PATCH, $RESTART_NO_REBOOT), '/crash')
EndIf
AdlibRegister('_Countdown', 1000)
Do
Until GUIGetMsg() = -3
Func _Countdown()
Local $tData, $iData
$Count -= 1
If $Count Then
GUICtrlSetData($Label, 'The application will be crashes after ' & $Count & ' seconds.')
Else
; Forced script crash due to a memory access violation
$tData = DllStructCreate('int', 0x12345678)
$iData = DllStructGetData($tData, 1)
EndIf
EndFunc ;==>_Countdown