Enumerating Shared Folders

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

For the most part, you should not share out every single folder on your computer. After all, doing so exposes all your documents and all your data to anyone browsing the network. Likewise, it potentially allows anyone to make changes to critical or confidential files and folders.

To guard against the possible misuse of shared folders, it is a good idea to periodically review the shared folders on a computer and then decide whether those folders should be shared at all. You can use the Win32_Share class to return information about the shared folders on a computer. The shared folder properties available through this class are shown in Table 11.11.

Table 11.11   Win32_Share Properties

PropertyDescription
AllowMaximumIndicates whether or not the number of users allowed to simultaneously access this folder has been limited. If True, the value in the MaximumAllowed property is ignored.
CaptionDescription of the object.
MaximumAllowedLimit on the maximum number of users allowed to use this resource concurrently. The value is valid only if the AllowMaximum property is set to False.
NameNetwork name given to the shared folder.
PathLocal path of the shared folder.
TypeType of resource being shared. Types include disk drives, print queues, interprocess communications (IPC), and general devices. Values are:

0 Disk drive

1 Print queue

2 Device

3 IPC

2147483648 Disk drive (Administrative share)

2147483649 Print queue (Administrative share)

2147483650 Device (Administrative share)

2147483651 IPC (Administrative share)

The relationship between the Win32_Share class and Windows Explorer is shown in Figure 11.9.

Figure 11.9   Win32_Share and Windows Explorer

Win32_Share and Windows Explorer

Scripting Steps

Listing 11.32 contains a script that enumerates the properties of all the shared folders on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_Share class.

    This returns a collection of all the shared folders on the computer.

  4. For each shared folder instance in the collection, echo the values for properties such as the shared folder name, the shared folder path, the maximum number of simultaneous connections allowed, and the shared folder type.

Listing 11.32   Enumerating Shared Folders

1 2 3 4 5 6 7 8 9 10 11 12 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share") For Each objShare in colShares     Wscript.Echo "Allow Maximum: " & vbTab & objShare.AllowMaximum        Wscript.Echo "Caption: " & vbTab & objShare.Caption        Wscript.Echo "Maximum Allowed: " & vbTab & objShare.MaximumAllowed     Wscript.Echo "Name: " & vbTab & objShare.Name        Wscript.Echo "Path: " & vbTab & objShare.Path        Wscript.Echo "Type: " & vbTab & objShare.Type    Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net