Network Object

The Wscript Network object provides access to network resources and information. The ID for the object is Wscript.Network.

To create an instance of the Wscript Network object, pass the argument Wscript.Network to the Wscript.CreateObject method:

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

Table 9-15 lists the Network object properties

Table 9-15. Network object properties

Property

Description

ComputerName

Name of computer

UserName

Name of user logged into the machine

UserDomain

Name of domain user is currently logged into

The following example displays the name of the user logged into the machine:

Set objNetwork = CreateObject("Wscript.Network")
Wscript.Echo "You are logged on as " & objNetwork.UserName

EnumNetworkDrives

EnumNetworkDrives returns a collection of the currently connected network drives. The collection that is returned is a special WSH collection; it doesn’t operate the same way as other object collections.

For each connected drive, the collection contains an item for the drive letter and another item for the connected share name. If you have three connected network drives (K:, S:, and Y:), the collection contains six elements, the first element being the K: drive, the second being the share to which K: is connected, and so on.

Set objNetwork = Wscript.CreateObject("Wscript.Network") 
Set objShares = objNetwork.EnumNetworkDrives( )
Wscript.Echo "Drive " & objShares(0) & " is connected to " & objShares(1)

The following example ...

Get Windows XP in a Nutshell, Second Edition 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.