VBScript - Windows Scripting Host (The WshNetwork Object)

April 2017



The WshNetwork object contains information about the Microsoft Windows Network, as well as methods to manage (login, logout) printers and network shares.

The WshNetwork object is obtained by creating an instance of the COM object identified by the "WScript.WshNetwork" progID:
Set WshNetwork = CreateObject("WScript.WshNetwork")



Here is a summary of the properties and methods of the WshNetwork object:

Objet WshNetwork
Collections Propriétés Méthodes
ComputerName
UserDomain
UserName
AddPrinterConnection
EnumNetworkDrives
EnumPrinterConnections
MapNetworkDrive
RemoveNetworkDrive
RemovePrinterConnection
SetDefaultPrinter

The methods of the WshNetwork object


The methods of the WshNetwork object are:

MethodDescription
AddPrinterConnection(strLocalName, strRemoteName [,bUpdateProfile] [,strUser]

[,strPassword])
Allows you to map a local printer (strRemoteName) on a local resource (strLocalName). When the optional argument "bUpdateProfile" is True , the printer is stored

in the user profile. strUser and strPassword can optionally specify a user other than the current account.
WshNetwork.AddPrinterConnection("LPT1", "\\Server\printer")
EnumNetworkDrives()Returns a collection of objects corresponding to the network drive mappings in the system.
EnumPrinterConnections()Returns a collection of objects that match the network printer mappings in the system..
MapNetworkDrive(strLocalName, strRemoteName [,bUpdateProfile] [,strUser]

[,strPassword])
Allows you to map a network share (strRemoteName) on a local resource (strLocalName). When the optional argument "bUpdateProfile" is True , the network drive is

stored in the user profile. strUser and strPassword can optionally specify a user other than the current account.
WshNetwork.MapNetworkDrive("J:", "\\Server\Share")
RemoveNetworkDrive(strName[,bForce[,bUpdateProfile]])Deletes the specified network connection using strName argument. The optional argument bForce when is True, remove the disable connection to the

network drive while it is in use. bUpdateProfile when True, removes the drive from the network profile.
WshNetwork.RemoveNetworkDrive("J:";)
RemovePrinterConnection(strName[,bForce[,bUpdateProfile]])Disable the connection to the printer specified by strName argument. he optional argument bForce when is True, remove the disable connection to the

network drive while it is in use. bUpdateProfile when True, removes the printer from the network profile.
WshNetwork.RemovePrinterConnection("LPT1:";)
SetDefaultPrinter(strPrinterName)Sets the remote printer specified strPrinterName printer, as the default printer.
WshNetwork.SetDefaultPrinter("\\Server\Printer")

Properties of the WshNetwork object


The Properties of the WshNetwork object are:

PropertiesDescription
ComputerNameContains a string describing the name of the computer.
UserDomainContains a string describing the domain name on which the computer is connected.
UserNameContains a string describing the name of the user.



Original document published on CommentcaMarche.net

Related


Published by deri58. Latest update on March 16, 2013 at 04:42 AM by deri58.
This document, titled "VBScript - Windows Scripting Host (The WshNetwork Object)," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).