CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Reporting on Network Drives

You might like to have a script that tells you what network drives you have available. The following script does this by using the Wsh.Network object. An instance of this is created below by using the CreateObject method. Then you can use this object's properties and methods to obtain information, to map network drives, etc.

' Filename:  drives.vbs
' Author:  Br. David Carlson
' Date:  July 29, 2001
' This WSH script reports on mapped network drives.

Dim net
Dim drives
Dim k
Dim num
Dim msg

set net = Wscript.CreateObject("Wscript.Network")

set drives = net.EnumNetworkDrives

if drives.Count = 0 then
   Msgbox "No mapped network drive"
   num = drives.Count
   msg = num / 2 & " mapped network drive(s)" & vbCRLF
   for k = 0 to num - 1
      msg = msg & drives(k) & vbCRLF
   Msgbox msg
end if

EnumNetworkDrives is a method that returns a collection of data, here named drives, about the network drives. Any collection has a Count property and an Items property. The Count property reports the number of items in the collection. Note that the above script divides this number by 2 since each drive is reported twice. (For example, as P: and as \\cisdept\public.) We could access the name of each drive as drives.Item(k), but drives(k) is a shorter way to access the same thing. (This is because Item is the default property for collections.)

Note that each variable is declared in VBScript via a Dim statement. Msgbox is used to display a message in a dialog box. The & concatenation operator is used by our script to keep appending new information to the msg string until we are ready to display it in a dialog box. The vbCRLF constant is obviously a carriage return/line feed combination.

Back to the Using WSH to Automate Tasks page

Author: Br. David Carlson
Last updated: February 11, 2007