Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Writing Portable Scripts 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 
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

Writing Portable Scripts in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-04-18

    Table of Contents:
  • Writing Portable Scripts in WSH
  • Scripting Environmental Variables
  • Using Environmental Variables
  • Using Special Folders

  • 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


    Writing Portable Scripts in WSH - Using Special Folders


    (Page 4 of 4 )

    WSH also provides another simple way of accessing common system folders known as the WshSpecialFolders collection.  Depending on the current version of Windows, the collection contains the folders in the following table.

    AllUsersDesktop

    Common desktop

    AllUsersStartMenu

    Common start menu

    AllUsersPrograms

    Common “All Programs”

    Desktop

    Current user’s desktop

    Favorites

    Current user’s Favorites

    Fonts

    System fonts

    MyDocuments

    Current user’s Documents

    NetHood

    Network Neighborhood or My Network Places

    PrintHood

    Printers and Faxes

    Programs

    Current user’s “All Programs”

    StartMenu

    Current user’s start menu

    Templates

    Templates folder

    AppData

    Application Data

    Recent

    Recent documents

    SendTo

    Send To folder

    Using the WshSpecialFolders collection makes accessing any of these folders very easy and efficient.  Consider what we went through to connect to the current user’s desktop in our earlier example and compare it to the following:

    Set WshShell = CreateObject("WScript.Shell")

    Set WshSpecialFolders = WshShell.SpecialFolders

    WScript.Echo WshSpecialFolders("Desktop")

    You can also perform a little shorthand by calling the SpecialFolders collection directly from the WshShell object.

    Set WshShell = CreateObject("WScript.Shell")

    WScript.Echo WshShell.SpecialFolders("Desktop")

    As you can see, both of the previous examples perform the same task.  The second example makes things a little easier by polling the WshSpecialFolders collection directly.

    By incorporating Environmental Variables and Special Folders you should be able to create more portable scripts.  It’s good practice to employ these techniques all of the time.

    I will offer one word of caution if you are using environmental variables in a script that is designed to be used as a Schedule Task.  It won’t work.  Unfortunately, you’ll have to resort to either the SpecialFolders collection or hard-coded paths.

    One last thing to consider when writing portable scripts is software versions.  Many times there are substantial differences between different Windows releases.  The same holds true for components such as the Windows Script Host.

    If you’re employing code that was not available in a previous version, it is good to do a quick error check to make sure the proper version is available.  Unfortunately, I’m out of space so that will have to wait for another article.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · If you're designing scripts for distribution, it's better to be safe than sorry. In...
     

    WINDOWS SCRIPTING ARTICLES

    - 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
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





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