Guy’s Scripting Ezine 75 –  List a Computers Shares, Out-Takes

Contents for Ezine 75 List Shares – Out-takes

This Mission – To Display Network Shares

What this week’s script will do is to display shared folders and printers.  In the first example, we have to hard-code the name of the server in the script itself.  The second script not only provides an inputbox for you to interrogate different servers, but also lists the shares in one long list.  The first example is easy scripting but laboriously echoes each share in turn.  It drove me mad because I had to keep clicking OK on each share’s message box.  The second share builds up a list of all shares then displays them all in one long list.

Start – Check the basic scripts

I suggest that you start with the working scripts, then try and correct these mistakes.

Out-take 1 – To Map to Display Network Shares

Here is a simple script, which should interrogate a servers operating system, and then echo each shared folder or shared printer.

Instructions for displaying a servers shares

  1. Copy and paste the script below into notepad.
  2. Double click the script, then detect and repair the error
 

‘ ListShare.vbs Windows Logon Script
‘ VBScript List Shares on a Server
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Ezine 75 Out-Take 1.2 – May 2005
‘ —————————————————-‘
Option Explicit
Dim objFs, objShare
Dim strServer

‘ The section sets the variables
strServer = "GuyServer"

‘ Connects to the operating system’s file system
set objFs = GetObject("WINNT://" _
& strServer & "/LanmanServer,FileService")

‘ Loops through each share
For Each objShare In objFs
WScript.Echo objShare.name
Next

End of List Share VBScript

Learning Points for Listing Shares

Note 1:  Pay attention to case sensitive commands

Out-Take 2 – To Map to Display Network Shares

 

‘ ListShare.vbs Windows Logon Script
‘ VBScript List Shares on a Server
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Ezine 75 Out-Take 2.3 – May 2005
‘ —————————————————-‘
Option Explicit

Dim objFs, objShare
Dim strServer, strList

‘ The section sets the variables
strList = " ————————— "
strServer = "alan"

‘ Creates the Input Message Box
strServer = InputBox("Server to list shares: "_
," Share List", strServer)

‘ Connects to the operating system’s file system
set objFs = GetObject("WinNT://" _
& strServer & "/LanmanServer,FileService")

‘ Loops through each share
For Each objShare In objFs
strList = strList & vbCr & LCase(objShare) _
& " " & vbTab & UCase(objShare.Description)
Next

WScript.Echo strList

End of List Share VBScript

Learning Points for Example 2

Note 1: Review the Object, Property syntax.

Answers

Out-Take 1.  Should be WinNT not WINNT

Out-Take 2.  You need the name property, objShare.name not objShare