Handling User Input in WSH - Prompting Users in Wscript
(Page 5 of 6 )
Since the StdIn and StdOut objects are only available in Cscript, we have to find other ways of handling user input when using the Wscript engine. This is most easily done using VBscript's InputBox and MsgBox functions.
The InputBox first creates a dialog box with a text field for user input. Then, the user optionally enters information and then clicks either the OK or Cancel button. The InputBox function returns a string result after one of the buttons is pushed.
Pushing the Cancel button on an InputBox dialog will return an empty string regardless of what the text box contains.
The MsgBox function will create a dialog box without any method of user input. Message boxes are very flexible, allowing you to change both the message icon and the available buttons.
InputBox(Prompt[, [Title], [Default], [Xpos], [Ypos], [HelpFile][, Context]]
MsgBox(Prompt[, [Buttons], [Title | Helpfile[, Context]]
The InputBox function requires a Prompt string that will be presented to the user. The remaining attributes are all optional. The Title attribute is the string displayed as the dialog box title; the Xpos and Ypos are used to manually position the box from the left and top of the screen, respectively; and the Helpfile attribute specifies a help file associated with the input box. An optional context attribute can be used with the HelpFile attribute to indicate a specific context number in the help file.
Constant | Value | Button |
VBOK | 1 | OK |
VBCancel | 2 | Cancel |
VBAbort | 3 | Abort |
VBRetry | 4 | Retry |
VBIgnore | 5 | Ignore |
VBYes | 6 | Yes |
VBNo | 7 | No |
The MsgBox function’s only required attribute is the Prompt. The Title attribute provides a title for the dialog box. The Button attribute defines what buttons will be displayed. You can use a combination of either constants or values listed in the table below. The button attribute defaults to 0. The MsgBox function returns a value base upon the button pushed. The possible values are listed in the table to the left.
OPTIONAL BUTTON VALUE ARGUMENTS |
CONSTANT | VALUE | DESCRIPTION |
VBOKOnly | 0 | Show OK button |
VBOKCancel | 1 | Show OK and Cancel |
VBAbortRetryIgnore | 2 | Show Abort, Retry, Ignore |
VBYesNoCancel | 3 | Show Yes, No, Cancel |
VBYesNo | 4 | Show Yes and No |
VBRetryCancel | 5 | Show Retry and Cancel |
VBCritical | 16 | Show critical message icon |
VBQuestion | 32 | Show warning query icon |
VBExclamation | 48 | Show warning icon |
VBInformation | 64 | Show information icon |
VBDefaultButton1 | 0 | First button is default |
VBDefaultButton2 | 256 | Second button is default |
VBDefaultButton3 | 512 | Third button is default |
VBDefaultButton4 | 768 | Fourth button is default |
VBApplicationModal | 0 | User must respond before the application will continue |
VBSystemModal | 4096 | User must respond before any application will continue |
Next: Wscript Examples >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer