CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Another Way to Report on Network Drives

Much of the code in this example is the same as that in the Reporting on Network Drives example. However, we have created a Wsh.Shell object, here named shell, and used its Popup method to ask the user a question. The "Report on network drives?" question is shown in a dialog box with yes and no buttons for the user to click. (The latter are indicated by the vbYesNo constant.) The vbQuestion constant results in a question mark icon being placed on the dialog box. The 4 parameters to Popup are: the text to display, number of seconds to wait, title for the dialog box, and flags (such as vbYesNo, possibly combined using + signs). In the drives2.vbs script, the program will assume an answer of No if the user doesn't click a button within 4 seconds. In that case, no drive information is displayed.

' Filename:  drives2.vbs
' Author:  Br. David Carlson
' Date:  July 29, 2001
' This WSH script gives the user the option of getting a
' report on all network drives.

Dim net
Dim shell
Dim answer
Dim drives
Dim k
Dim num
Dim msg

set net = Wscript.CreateObject("Wscript.Network")
set shell = WScript.CreateObject("WScript.Shell")

answer = shell.Popup("Report on network drives?", 4, "Network drive report", vbYesNo + vbQuestion)

if answer = vbYes then
   set drives = net.EnumNetworkDrives

   if drives.Count = 0 then
      Msgbox "No mapped network drives"
      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
end if

Finding out the Details on WSH Objects

Note that there are many other possible flags that can be used with Popup. How do you find out about these flags? Or, in general, how do you find out about other WSH-related objects as well as their properties and methods? The best method (short of a good reference book) is to go to MSDN's page on Windows Script Host Basics. Fill in "WSH Popup" or whatever you want to search for in the MSDN library search engine.

Back to the Using WSH to Automate Tasks page

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