WSH » Objects » wshnetwork

The WshNetwork object exposes the network functionalities of Microsoft Windows, making it easy to manage drives and printers on the network. The WshNetwork object is not instantiated automatically upon script execution, hence it must be instantiated explicitly using CreateObject before it can be used.

Through the WshNetwork object one can query some of the network related information about a local computer, connect to drives and printers on the network, map and unmap network drives, set default printer, and disconnect from drives and printers on the network.

Properties

ComputerName

Syntax: WshNetwork.ComputerName

The ComputerName property is read only and returns a string which is the current computer's name.

UserDomain

Syntax: WshNetwork.UserDomain

The UserDomain property is read only and returns a string which is the current user's domain name.

UserName

Syntax: WshNetwork.UserName

The UserName property is read only and returns a string which is the current user's name.

Methods

AddPrinterConnection

Syntax: WshNetwork.AddPrinterConnection (strLocalName, strRemoteName [,bUpdateProfile] [,strUser] [,strPassword])

The AddPrinterConnection method makes a connection to a remote printer.

AddWindowsPrinterConnection

Syntax: Win 95/98: WshNetwork.AddWindowsPrinterConnection(strPrinterPath, strDriverName [,strPort])

Win2000/NT: WshNetwork.AddWindowsPrinterConnection (strPrinterPath)

The AddWindowsPrinterConnection method adds a printer connection to Windows. This method reqires different number of arguments depending on the version of Windows the script is running on.

EnumNetworkDrives

Syntax: WshNetwork.EnumNetworkDrives ()

The EnumNetworkDrives method returns a collection of the current network drive mappings.

EnumPrinterConnections

Syntax: WshNetwork.EnumPrinterConnections ()

The EnumPrinterConnections method returns a collection of the current network printer mappings.

MapNetworkDrive

Syntax: WshNetwork.MapNetworkDrive (strLocalName, strRemoteName [,bUpdateProfile] [,strUser] [,strPassword])

The MapNetworkDrive method maps a remote drive onto a local drive letter.

RemoveNetworkDrive

Syntax: WshNetwork.RemoveNetworkDrive (strName, [,bForce] [,bUpdateProfile])

The RemoveNetworkDrive method removes a previously mapped network drive.

RemovePrinterConnection

Syntax: WshNetwork.RemovePrinterConnection (strName, [,bForce] [,bUpdateProfile])

The RemovePrinterConnection method removes a previously connected netword printer.

SetDefaultPrinter

Syntax: WshNetwork.SetDefaultPrinter (strPrinterName)

The SetDefaultPrinter method sets the default printer to the specified printer.