Skip to content

$InputObject.CloseMessageBox

Closes a MessageBox That was created as async, and is not needed any longer.

If you have called ShowMessageBox with async = $true and have reached a point in the installation where the MessageBox is no longer current, you can either show a new MessageBox with new information, which will close the already shown MessageBox, or you can simply close the initial MessageBox with CloseMessageBox()

It does not matter if the MessageBox, you are trying to close;

  • still exists, waiting for the user to click it,
  • the user has already clicked it,
  • has closed by itself, because it reached the timeout, it was created with.

void $InputObject.CloseMessageBox()

None

None

Terminal window
$cs.Job_WriteLog("Showing MessageBox")
$messageBoxResponse = $InputObject.ShowMessageBox("Do not turn off", "Please do not turn off your computer. Hardware drivers are being installed", "OK", "ONE", "Info", 300, $true)
$cs.Job_WriteLog("response: $messageBoxResponse")
# for testing, wait 5 seconds
Start-Sleep -Seconds 5
$cs.Job_WriteLog("Closing MessageBox")
$InputObject.CloseMessageBox()
$cs.Job_WriteLog("MessageBox closed")

Closing an async MessageBox early because the underlying condition it was warning about has already been resolved, without waiting for the user or the timeout:

Terminal window
$cs.Job_WriteLog("Showing MessageBox")
$InputObject.ShowMessageBox("Please wait", "Waiting for the network connection to become available", "OK", "ONE", "Info", 600, $true)
$Retries = 0
while (!(Test-Connection -ComputerName "8.8.8.8" -Count 1 -Quiet) -and $Retries -lt 30) {
Start-Sleep -Seconds 2
$Retries++
}
$cs.Job_WriteLog("Network is available, closing MessageBox")
$InputObject.CloseMessageBox()

Scripting Guidelines

Sys_BreakthruMsgbox $InputObject.ShowMessageBox