Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - Handling User Input in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Handling User Input in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-02-19

    Table of Contents:
  • Handling User Input in WSH
  • Command Line Arguments
  • Using Named Arguments
  • Prompting Users in Cscript
  • Prompting Users in Wscript
  • Wscript Examples

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Being able to handle user input gives your scripts a level of flexibility you can't...
     

    WINDOWS SCRIPTING ARTICLES

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway