WMI: VBscript to show the network shares of a computer

Posted February 9th, 2010 in shares by dirk adamsky

Okido, here’s another starter script.
This script shows all network shares on your computer.
Default computer is the local machine.
When the dot is replaced by another machine name the script works against that machine.
With some additions the script can be used for a simple inventory of the pc’s in your network.

There are some conditions that must be met:

  1. the script must be run with administrative credentials
  2. the firewall of the remote machine needs the following ports opened for WMI: TCP 135, TCP 4168 and
    UDP 9256

Follow the next steps to make and run the script (admin rights needed):

  • open your favorite text editor (mine is notepad++)
  • copy and paste the script into the editor (delete the line numbers)
  • save the script (for example c:tempenumerateshares.vbs)
  • open a command prompt
  • go to “c:temp”
  • give “cscript enumerateshares.vbs” (without quotes) and enter

The script:

' Name : enumerateshares.vbs
' Description : script to show the model of a computer
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 09-02-2010
' Level : beginner

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
Wscript.Echo "name ; path ; caption"
For each objShare in colShares
    Wscript.Echo objShare.Name & " ; " & objShare.Path & " ; " & objShare.Caption
Next
Set colShares = Nothing
Set objWMIService = Nothing

As said earlier: when you have questions/problems please give a reply.

Best regards,

Dirk Adamsky – Deludi BV