函数参考


_WinAPI_RegisterApplicationRestart

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 标志可能包含一个系统错误代码.

注意/说明

Your initial registration for restart must occur before the application encounters an unhandled exception
or becomes unresponsive. You could then call this function from inside your recovery callback to update the
command line. To prevent cyclical restarts, the system will only restart the application if it has been
running for a minimum of 60 seconds.

If you register for restart and the application encounters an unhandled exception or is not responsive,
the user is offered the opportunity to restart the applicationthe application is not automatically restarted
without the user's consent.

本函数需要 Windows Vista 或更高版本系统.

相关

详情参考

在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