Custom Message Box
Posted on July 25, 2019
This custom message box is designed as a replacement for the built-in CWA message box used for reboot prompts. However, it allows you to customize the colors, message, buttons, actions from the buttons, and responses from those buttons so that you have a better handle on the user response (or lack thereof). This is a standalone EXE that you would transfer via script from your CWA server using the File Download function.
Download the CustomMessageBox.zip file from here and drop the EXE file in your LT share directory or anywhere else you’d like to have it available for download by client computers.
The argument includes the word(s) AND the equal sign to identify the value. Do not enter a space character between the equal sign and argument value. All argument values should be enclosed in double-quotes if a space, equal sign, or some other special characters are used – or just in case to make sure things work as intended. To use double-quotes within a string, escape it with a backslash (eg: message=”This is a \”quoted\” message”).
|Header=||Specifies the title of the message box window.|
|Button=||Adds a button to the bottom of the prompt.|
|RebootButton=||Adds a button that will forcibly restart the computer when pressed. Uses the command “shutdown /f /g /t 30 /d p:0:0 /c “”Planned MSP-initiated Reboot. User approved.”” (where “User approved” shows “Timer expired” if a timer is used and runs out).|
|ShellButton=||Adds a button that will start a process when pressed. See ShellPath below.|
|ShellPath=||This is the full file path, and arguments, for the desired process to start when ShellButton is used.|
|WebButton=||Adds a button that will launch a website with the default browser. See WebPath below.|
|WebPath=||This is the url at launch when WebButton is used.|
|Icon=||This is the full file path to an icon to show in the title bar. If needed, use double quotes around the file path. This must be a .ico file. If the file doesn’t exist, no icon is shown.|
|OnTop=||This can be 1 or 0. Defaults to 0. If set to 1 keeps the window on top.|
|Theme=||Can be light (default), dark, red, blue, win10, or xp.|
|Position=||Can be center (default), topleft, topright, bottomleft, bottomright. Sets the starting location for the window. It can be moved by the user, but will start in the center or specified corner of the “primary” screen.|
|Status=||The full file path for a text file for displaying dynamic status messages. See details below.|
|AutoClose=||Can be 1 or 0. Defaults to 0. Determines if the message box automatically closes when the Status argument is used. Only valid when Status is used.|
If the user presses Escape or Alt-F4 to close the window, the string “Exited” is returned.
Button information and arguments:
Up to 5 buttons may be added and are added in the order specified from right to left. The first button added will be on the right side and will be default should a user press Space or Enter with the window open. If no button is added, a default button with the caption and return text “OK” is added. Buttons need 1, 2, or 3 arguments in a specific order, with each argument separated by a pipe “|”. The order is caption, return text, count down time (in seconds). A pipe character should not be used in the caption or return text and should ONLY be for argument separation.
Button arguments (applies to Button, RebootButton, ShellButton, WebButton):
|Caption||Optional, First||The text that appears on the button.|
|ReturnText||Optional, Second||The text that is returned to the console when the button is pressed. If not provided, defaults to caption.|
|CountdownTimer||Optional, Second if ReturnText is not used, third if ReturnText is used||The number of seconds to count down. If the timer expires this button is pressed as if the user clicked it. The seconds are converted to an HH:mm:ss string, where HH: only displays if the time is at least an hour. When combined with Reboot/Shell/Web button, the associated action will occur.|
The file path is not checked for validity, but a message box is shown if there is an error launching the process. Multiple ShellPath arguments can be provided, but only the last one will be used. Similarly, multiple ShellButton arguments can be used, but they will all receive the same ShellPath. If no ShellPath is provided with a ShellButton, the button will simply return the ReturnText value.
The value is checked only to confirm that it has parts of a url in it and does not validate the url further. This will launch with the default browser, similar to opening a website from start->run. If a specific browser is needed, it would be better to use a ShellButton and specify the path to the desired browser and append the url (eg: shellpath=”\”C:\Program Files\internet explorer\iexplore.exe\” “).
The Status argument allows you to have data dynamically loaded into the message. For instance, say you want to perform a variety of steps using another tool in the background, and you want the custom message box to show the progress of that. The Status argument should point to a text file (.txt or .log extension) with the information you’d like displayed in the prompt. The text file is polled every second and the contents are shown in the custom message box. When the last line of the text document is simply “Done” (or a variation with “X” at the beginning and/or spaces), status polling stops. Some additional notes:
- If the file specified doesn’t exist, no prompt will be displayed and a message returned will indicate the file couldn’t be found.
- If the file exists but is blank, “Waiting …” is shown in the custom message box.
- The header shows a running time ( mm:ss ) for how long the custom message box has been open.
- Once “Done” is found as the last line in the Status file, the timer stops.
- Button arguments are ignored. The only button that is created with the Status custom message box is “OK”.
- If AutoClose is set to 1, the “OK” button will change to a countdown of 30 seconds once “Done” is reached. This will cause the custom message box to automatically close without user intervention.
- Output is different for Status custom message boxes:
- If the user exits via Alt-F4 or by pressing Escape, the output is “Exited in XX seconds.”, where XX is the number of seconds that the time counted before “Done” was reached (if at all).
- If the user clicks OK before “Done” is reached, the output is “OK after XX seconds.”
- If the user clicks OK after “Done” is reached, or if auto close is used and expires, the output is “Completed after XX seconds.”
- Message argument is ignored – the message displayed is from the status file.
- Other arguments – header, icon, ontop, theme, position – are still honored.
- If Position is set to bottomleft or bottomright, the custom message box will remain in that corner and will continue expanding up as new lines are added to the Status file. However, if the user moves the custom message box, it will remain where the user leaves it and continue expanding down as needed.
- Consider the following command:
- CustomMessageBox.exe status=c:\windows\temp\status.log header=”Setup in progress…”
- The file c:\windows\temp\status.log will then be read every second and will be shown in the custom message box.
- As lines are added to status.log, they are automatically shown.
- The header would show the text “Setup in progress…00:01” with the timer counting up every second.
- Once complete, add a line of “Done” to stop automatically polling the text file, as well as stopping the timer in the header.
- Useful for step-by-step actions. The status file may contain the steps below, added as each step of the background process runs:
- Installing Application 1
- Installing Application 2
- Activating applications
- Show a simple message box with 2 lines in the message, and only an OK button (default).
- Show a message box with OK and Cancel buttons that return the same text as their caption.
- Show a prompt with the options to either remind in 5 minutes or force the reboot now. The Remind Me button will not cause a reminder to reappear, but will instead return the text “remindme”. You’ll need to reschedule a follow-up as needed based on this output.
- CustomMessageBox.exe header=”Reboot Needed” message=”Updates have been installed on your computer and a reboot is needed to complete this process. Please click \”Reboot Now\” to initiate a reboot now, or click \”Remind me …\” to be reminded tomorrow.\r\n\r\nNote: You can also manually reboot at any time to stop these reminders until a reboot is needed again.” button=”Remind me in|remindme|300″ rebootbutton=”Reboot Now” icon=”c:\windows\ltsvc\labtech.ico”
- Show a prompt to either reboot the computer or launch a notepad window.