Tip
cscript is the command-based script host. There are times when the script runs without the cscript command, but if you want to ensure the script runs without problems, you should use cscript.
cscript c:\scripts\logon.vbs
3. Displaying a Message Box with a Visual Basic Script
There are many times when you want to create a
pop-up message box to provide feedback to the user, or even to send a
message to a user after logon. The basic syntax is
msgbox "message ",[msg-box-style], "title"
msgbox Commands | Comments |
---|
Display a basic message.
msgbox "Only Pearson employees should use this computer.", vbinformation, "Warning"
| Displays a simple message to the user. It includes an information icon and the title bar includes the text “Warning.” |
Add blank lines in a message.
msgbox "Only Pearson employees should use this computer." & vbcrlf & vbcrlf & "If you are not an employee of Pearson, you should terminate this session immediately.", vbinformation, "Warning"
| If you have a long message, you can choose where line breaks are added with the vbcrlfFigure 1 shows how script is displayed when it is executed.
constant.
Note
The msgbox command is entered as a single line in Notepad without pressing Enter at all.
|
The following table shows some of the message box styles you can use as the second parameter in a dialog box.
Note
These styles are actually constants (integers). For example, vbinformation is a constant for the number 64. You can enter the integers instead but the constants are easier to remember.
Style | Comments |
---|
vbinformation | Shows a white “i” in a blue circle. |
vbexclamation | Shows a black exclamation mark in a yellow triangle. |
vbcritical | Shows a black “x” in a red circle. |
vbquestion | Shows a white “?” in a blue circle. |
vbokonly | Displays OK button only (default). The OK button has a return value of 1. |
vbokcancel | Displays OK and Cancel buttons. The OK button has a return value of 1 and Cancel returns 2. |
vbabortretryignore | Displays Abort, Retry, and Ignore buttons. The Abort button has a return value of 3, Retry returns 4, and Ignore returns 5. |
vbyesnocancel | Displays Yes, No, and Cancel buttons. The Yes button has a return value of 6, No returns 7, and Cancel returns 2. |
vbyesno | Displays Yes and No buttons. The Yes button has a return value of 6, and No returns 7. |
vbretrycancel | Displays Retry and Cancel buttons. The retry button has a return value of 4, and Cancel returns 2. |
msgboxsetforeground | Sets the message box as the foreground window. |
You can combine the buttons using the plus character (+) to concatenate message box styles. For example, if you want to use the question mark icon with the YesNo buttons, you can use the following code: vbquestion + vbyesno. and