Windows Scripting
  Home arrow Windows Scripting arrow 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 
Actuate Whitepapers 
Moblin 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Handling User Input in WSH


    (Page 1 of 6 )

    Many of the scripts you write will require some form of user input. Whether the user is supplying some direction for the script or merely providing information that the script cannot determine on its own, this is a very common and useful technique. We’re going to explore some of the more common ways to handle user input.

    There are basically two different ways to request user input for your script.  The first is by using run time parameters supplied by the user at the time of script execution.  The second is by accepting a user’s response to a prompt during the script’s execution.

    We’ll start by learning how to handle parameters that are passed as arguments during the script’s execution.  WSH allows for argument passing in two ways.  You can supply them in the command line used to execute the script or you can drag-and-drop files onto a script’s icon.

    The first is the method of choice for running a script with the Cscript engine and the second is the better choice for executing through the Wscript engine.  However the two methods are not exclusive to these recommendations.

    Using drag-and-drop to pass files or folders to a script will execute the script using the default scripting engine.

    WSH provides a native object for us to handle these arguments called the WshArguments object.  The WshArguments object returns a read-only collection of items that were passed during execution.  The WshArguments object is returned by the Wscript object’s Arguments property.

    object.Arguments

    The process of handling the object and arguments is the same regardless of which method was used to pass them.  Let’s take a look at the methods and properties provided by the WshArguments object.

    Methods

    object.Count

    object.Item([Index])

     

    Properties

    object.length

    The WshArguments object contains a collection of argument items.  The Count method is used to return a Long value indicating the number if items in the collection.  The Item method is used to return a specific item in the collection corresponding to the supplied zero-based Index value.

    The length property returns a Long value indicating the number of items in the collection.  For consistency when using Jscript, this length property should be typed in lower case.

    Set colArgs = Wscript.Arguments

    For Each Arg In colArgs

       Wscript.Echo Arg

    Next

    This simple loop will iterate through each of the supplied arguments and Echo them back to the user.  This is a very basic method of processing these arguments.

    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

    - 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
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory




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