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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
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

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

    - 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...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT