Understanding Windows Script Host Basics
We assume you have Microsoft Windows Script Host 5.6 installed. If you aren’t sure, open a
command prompt and type cscript //logo //?. You should see something like this.
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
//B :Batch mode: Suppresses script errors and promptsfrom displaying
//D :Enable Active Debugging
//E :engine Use engine for executing script
//H :CScript Changes the default script host to CScript.exe
//H :WScript Changes the default script host toWScript.exe (default)
//I :Interactive mode (default, opposite of //B)
//Job :xxxx Execute a WSF job
//Logo :Display logo (default)
//Nologo :Prevent logodisplay: No banner will be shown at execution time
//S :Save currentcommand line optionsfor this user
//T :nn Time outin seconds: Maximum time a script is permitted to run
//X :Execute script indebugger
//U :Use Unicode for redirected I/O from the console
In the next sections, we’ll cover a few key WSH elements that recur in our scripts throughout
the book.
Note Many of the scripts and samples in this book require administrator privileges, either
locally or on remote systems. We assume you will be running any scripts as a local or domain
administrator. Where appropriate, we will point out how and where to use alternate credentials.
WshShell
The WshShellobject offers a lot of functionality to scripting administrators. You can use it to
send a message to the user through a popup, read and write to the registry, launch other programs, and more. Let’s take a quick look at this object.
Popup
The Popupmethod displays a graphical message to the user, complete with buttons and icons.
One advantage to using the Popupmethod instead of the similar MsgBoxfunction (discussed
later in this chapter) is that you can configure the popup window to dismiss itself automatically after a specified number of seconds. This is ideal when you want to display information
to a user but you don’t want to rely on t he user to click OK. Listing 1-1 illustrates t he use of t he
Popupmethod with a sample script.
WshShell PopupSample
dim wshShell
set wshShell=CreateObject("wscript.shell")
'title for popup window
strTitle="Welcome"
'compose popup message text
strMsg="Thank you for logging in." & VbCrLf
strMsg=strMsg & "It is now " & Now & VbCrLf
strMsg=strMsg & "Havea nice day."
'set time to -1 to never dismiss popup window
wshShell.Popup strMsg,7,strTitle,vbOKOnly+vbInformation
Notice that we use some intrinsic constants, vbOkOnly and vbInformation, as part of our
popup parameters. These constants display the OK button and the information icon, respectively. These same constants are also used with the MsgBoxfunction. You can find more information about them in the Windows Script Host 5.6 documentation.
No comments:
Post a Comment