Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - WSH in Other Languages
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

WSH in Other Languages
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-08-11

    Table of Contents:
  • WSH in Other Languages
  • VBScript
  • Jscript
  • Python
  • More Languages

  • 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


    WSH in Other Languages - VBScript


    (Page 2 of 5 )

    Microsoft Visual Basic Scripting Edition (VBScript) is an Active Scripting language developed by Microsoft in 1996 with the release of Internet Explorer 3.0. The syntax is a subset of Microsoft’s Visual Basic programming language.

    VBScript is the most commonly used language in WSH because it is easy to learn and well-integrated throughout the Microsoft family of software. Its real-world command set and non-strict nature allow novice users to begin writing code very quickly.

    The VBScript engine comes integrated into the Windows Script Host environment.  Simply naming a plain text file with a .vbs extension is all that is required to make the script executable.

    Accessing COM Objects

    As an object-oriented environment, WSH relies heavily on its ability to use COM objects installed on the system.  While the most commonly used objects are OLE automation objects, WSH (and VBScript) will allow you to connect to and use any COM-enabled library that has a scripting interface.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    In order to use objects and access their various properties, methods, and events you must first create an instance of the object in your script.  This is most commonly done using VBScript’s CreateObject method.

    Because VBScript is fully integrated into the WSH environment, intrinsic objects such as WSH’s WScript object model are readily available and do not require initialization.

    VBScript also provides a GetObject method that returns a reference to an object instance that is already running.

    Set objFolder = objFso.GetFolder("C:temp")

    The properties and methods of an object are accessed using standard object-dot syntax. In this case, the FileSystemObject’s GetFolder method is being used to return a Folder object that represents a supplied system path.

    Set colFiles = objFolder.Files

    Finally, the Folder object’s Files property is used to return a collection object containing object references for each of the files in the specified folder.

    Working with Collections

    Various scripting languages handle collection objects differently. Since collections are quite commonplace in the WSH environment, I’m including a section that covers this topic for each of the languages I present today.

    For Each objFile In colFiles

       WScript.Echo objFile.Name

    Next

    In VBScript, collections may be accessed directly. It provides a For Each…Next structure for iterating through each object in the collection.  Here, I’m quite simply just printing the file name back to the screen.

    Additional Notes About VBScript

    VBScripts provides a very relaxed programming environment. VBScript is not case-sensitive, nor does it require any line endings. It also ignores extraneous whitespaces; however, statements may not span more than one line without using the special underscore character. Finally, variables are all of type variant and may be explicitly declared, but this is not required.

    More Windows Scripting Articles
    More By Nilpo


       · The Windows Script Host is not limited to VBScript and JScript. In fact, you can...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek