O'Reilly logo

Windows XP in a Nutshell, Second Edition by Troy Mott, Tim O'Reilly, David A. Karp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required