Windows Scripting
  Home arrow Windows Scripting arrow Nilpo`s Scripting Secrets, Vol I
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

Nilpo`s Scripting Secrets, Vol I
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-12-15

    Table of Contents:
  • Nilpo`s Scripting Secrets, Vol I
  • Determine if a user is an Administrator
  • Wait for a program to end
  • More scripting secrets

  • 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


    Nilpo`s Scripting Secrets, Vol I


    (Page 1 of 4 )

    As I was going through my own personal script repository, I noticed that I had compiled quite a number of simple scripts and code snippets that I had either found or created to perform simple but often necessary scripting tasks. A good many of them are workarounds developed to add functionality that is otherwise unavailable in WSH or VBScript alone. I decided to package them up and offer them to my readers.

    Some of these are simple and may not appear to have any immediate use.  Others, however, you will find to be quite priceless. They are presented here in no particular order. If you don’t have a use for the code in particular, try to at least learn from them by seeing how their techniques were used to accomplish each task.

    Forcing a specific scripting engine

    As you well know, the Windows Script Host provides two different scripting engines: cscript.exe and wscript.exe.  While most scripts can be run equally well in one or the other, there are often times when one or the other is preferred or even necessary.  Since the default engine can be changed from system to system, it is nice to include some code in your script to force the use of a necessary engine for compatibility purposes.

    If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then

        strPath = WScript.ScriptFullName

        strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)

        CreateObject("WScript.Shell").Run(strCommand)

        WScript.Quit

    End If

    This simple If statement can be placed at the top of your script to force it to run using Cscript.exe. It uses the WScript object to determine the current scripting engine by examining the FullName property.

    If the script is running in the correct engine, the If statements exits and script execution continues. Otherwise, it launches the script again in the correct engine from the command line and then exits the first instance.

    More Windows Scripting Articles
    More By Nilpo


       · Thank you very much for those valuable tips.Reading your article gave me an...
       · Hi Patrick,You make a very good point, but there's one small mistake in your...
       · Sorry, you misread my comment. Reading every line but the last line was precisely...
       · My apologies. In that case your example is spot on. Thanks for sharing with our...
     

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek