Flylib.com

Books Software

 
 
 

VBScript Essentials


VBScript Essentials

The basis of scripting requires some familiarity with object-oriented programming (OOP), and terms such as objects, properties, and methods . These elements are the building blocks we use when we want to write a script not only for ISA Server, but for any script. The most essential element is an object, which can have one or more properties and one or more methods. To illustrate how these items relate to something we all know, think of a person (the object in this example). A person can have a first name, last name, and age, which are like properties. If a person needs to change his or her last name , he or she needs a method to do so.

Table 12-1 shows the basic terminology of scripting objects.

Table 12-1: Script Terminology

Name

Description

Example

Variable

A variable is a temporary place to hold data in a program. It is declared with the Dim statement.

Dim objRoot

Object

Objects are reusable software components that contain properties and methods and can be called by applications to perform certain tasks .

Set objRoot = CreateObject("FPC.Root")

Property

A property is either a value or a characteristic that is held by an object.

FPCComputer.Description = "Server"

Method

A method is a command that performs an action.

objFPCComputers.Save

Sub

A sub procedure is a part of code that does not return any value.

Sub WriteIT(value) Wscript.Echo value End Sub

Function

A function procedure is a part of code and can return a value.

Function TrimIT(value) TrimIT = Trim(value) End Function

When writing scripts against ISA Server you need to know what objects, properties, and methods the ISA server exposes and how to access and control them. Information on how to write scripts is included in the SDK for ISA Server 2004. We take a closer look at the ISA Server 2004 SDK as we are writing the scripts.

Tip 

You can download the ISA Server 2004 SDK from http://go.microsoft.com/?linkid=2392254 . The SDK can be used with both Standard Edition and Enterprise Edition.

Note that the naming convention used in all the samples is built on the object type prefix, and then the name of the COM object. This convention makes it easier to search the SDK for more information. An example of this naming convention would be objRoot , where obj is the prefix for an object and Root is the object itself. Table 12-2 illustrates other commonly used prefixes in VBScript.

Table 12-2: Common Naming Prefixes

Type

Prefix

Example

Boolean

bln

blnFound

Date

dtm

dtmStartTime

Integer

int

intCounter

Object

obj

objRoot

String

str

strComputerName



Preparing Your Environment

The first thing you should do is create a test lab in a virtual environment so that you can make mistakes without damaging your production environment. To complete the scripts described in this chapter, you need a domain controller and an ISA Server 2004 machine configured with two network adapters. Remember to isolate the test lab from your production environment before running any scripts.

Note 

See Chapter 19, "Configuring Microsoft ISA Server with Microsoft Virtual Server 2005," for more information about how to use Microsoft Virtual Server to configure a test environment. You can also use Virtual PC to configure a test environment. See the Microsoft Virtual PC site at http://www.microsoft.com/ windows /virtualpc/default.mspx for more information. In addition, you can download a 45-day trial version from there.

Installing ISA Server 2004 SDK

Once you have downloaded the ISA Server 2004 SDK from http://go.microsoft.com/?linkid=2392254 , you can install it by following these steps:

  1. On the ISA Server 2004 computer, log on as an administrator.

  2. Run ISA2004SDK.exe, and install with the default settings.

  3. The updated version of the ISA Server 2004 SDK will be located in C:\Program Files\Microsoft ISA 2004 SDK\HHelp\Isasdk.chm.

  4. Open a script editor.

Note 

You can download all of the sample scripts from this chapter at http://www.isamvp.com/apc .

Tip 

You can use the Microsoft Script Editor (MSE), which comes with Microsoft Office 2000 and later versions. To open the MSE, from the Tools menu of any Office application, select Macros, and then select Microsoft Script Editor. One other very useful editor that makes creating and working with scripts easy is PrimalScript, by Sapien Technology. You can download a trial version at http://www.sapien.com . If you don't have either of these tools, you can use Notepad.

Best Practices 

Create and test your scripts in a test environment—such as a test workstation, or a Virtual PC image—not on the ISA server itself.