WshNetwork Object

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The WshNetwork object provides your scripts with the ability to work with network drives and printers. It also provides your scripts with access to the name of the computer they are currently running on, as well as the domain and user names of the account under which they are running. This makes WshNetwork extremely useful in scripts that take actions based on such information as the name of the user logging on or the domain in which the user account resides.

The WshNetwork object can be used to accomplish some of the same tasks as the net.exe command-line tool. For example, the net name command returns the name of the user and the computer; the net use command is used to map and unmap network drives. These similarities make WshNetwork useful for converting legacy batch files and logon scripts that use net.exe to a WSH-based solution.

Table 3.21 lists the capabilities provided by the WshNetwork object, along with the methods and properties that your scripts can use to access this functionality.

Table 3.21   Capabilities Provided by the WshNetwork Object

CategoryMethod or Property
Working with network drivesMapNetworkDrive

EnumNetworkDrives

RemoveNetworkDrive

Working with network printersAddPrinterConnection

AddWindowsPrinterConnection

EnumPrinterConnections

SetDefaultPrinter

RemovePrinterConnection

Obtaining information about the currently logged-on userComputerName

UserDomain

UserName

WshNetwork is part of the Windows Script Host Object Model, wshom.ocx. The object model for the WshNetwork object is shown in Figure 3.15. In addition to the methods and properties provided by the WshNetwork object, WshNetwork also exposes a WshCollection object. The WshCollection object is not created using CreateObject but is automatically created and returned by the WshNetwork object s EnumNetworkDrives and EnumPrinterConnections methods.

Figure 3.15 shows the properties and methods of the WshNetwork object.

Figure 3.15   WshNetwork Object Model

WshNetwork Object Model

Accessing the WshNetwork Object

The WshNetwork object is a COM object, and an instance of the object can be created by the following code statement:

Set objNetwork = WScript.CreateObject("WScript.Network") 

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net