Chapter 6. VBScript and JScript Scripting Basics

Now that you know a bit about creating script files and running scripts, you are ready to start working with the features Windows Script Host has to offer. You'll find that WSH structures are surprisingly powerful. You can perform many advanced tasks with only a few basic commands.

Key WSH Objects

As you learned in Chapter 1, the WSH object model contains exposed and unexposed objects. Exposed objects are the ones you can access directly in your scripts and include WScript, WScript.WshNetwork, and WScript.WshShell. In this chapter, you work with basic methods and properties of each of these objects.

Table 6-1 lists the methods and properties of WScript.

Table 6.1. WScript Methods and Properties

Methods

Properties

CreateObject

Application

DisconnectObject

Arguments

Echo

FullName

GetObject

Name

Quit

Path

Sleep

ScriptFullName

 

ScriptName

 

Version

WScript.WshNetwork is the object you'll use to manage network resources such as printers and network drives. The methods and properties of this object are listed in Table 6-2.

Table 6.2. WScript.WshNetwork Methods and Properties

Methods

Properties

AddPrinterConnection

ComputerName

EnumNetworkDrives

UserDomain

EnumPrinterConnection

UserName

MapNetworkDrive

 

RemoveNetworkDrive

 

RemovePrinterConnection

 

SetDefaultPrinter

 

Another important object is WScript.WshShell. You'll ...

Get Microsoft® PowerShell, VBScript and JScript® Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.