The TWURegisterRestart function registers your (or a different) application for a restart when your application calls TWUCloseUpdate. This function is typically used after an in-place update, but can also be used if you want to start or restart a different application from a stand-alone update tool.

Note: The actual restart does not take place until TWUCloseUpdate is called; see the documentation of that function for details about the restart process.

URESULT TWURegisterRestart(
    TWUPDATE hUpdate,
    const TCHAR *pszAppPath,
    const TCHAR *pszOptions,
    DWORD dwFlags


[Input] Handle of active update session, created with TWUOpenUpdate.
[Input,optional] Fully qualified path to the application that must be [re]started during TWUCloseUpdate. If you pass NULL for this parameter, the current application's executable will be registered for restart; this is useful after an in-place upgrade.
[Input,optional] Any command line options to be passed to the restart application. Typically, this parameter is NULL, but if your application requires special processing after an upgrade, you can pass the corresponding command line options here.
[Input] Processing flags; see the section Processing flags below for details.

Return value

If the function succeeds, it returns ERROR_SUCCESS (0). If the function fails, it returns a nonzero Win32 API error code. You can use TWUGetErrorMessage to retrieve the error message that corresponds to the error code.

Processing flags

The dwFlags parameter can be a combination of the following values:

Value Description
TWU_UFLAGS_DEFAULT (0) Perform default processing only. This does not include any of the options below.
TWU_UFLAGS_CLOSEMAIN (0x00000001) Post a WM_CLOSE message to the application's main window immediately prior to the restart. This is the window whose handle was passed to TWUOpenUpdate.
TWU_UFLAGS_IMMEDIATE (0x00000002) Perform the restart as soon as TWUCloseUpdate is called instead of waiting until the main window is destroyed. This flag is mostly useful if you are restarting a different application; to restart the current application, do not specify this flag.
TWU_UFLAGS_CANCEL (0x80000000) Cancel any pending restart. You can use this option at any time prior to calling TWUCloseUpdate to prevent a restart. All other flags are ignored if you specify this flag.