Modifying Shared Folder Properties

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

As your network evolves, you might find it necessary to modify your shared folders. For example, you might need to limit the number of people who can connect to a shared folder at any one time. Alternatively, you might want to change the description of a shared folder, either to reflect a new use for that folder or to make it easier for users to identify the information stored in the folder.

The SetShareInfo method allows you to modify the maximum number of connections and the description of an existing shared folder. SetShareInfo accepts two parameters:

  • MaximumAllowed. The maximum number of users that can be connected to the share at one time. To allow unlimited simultaneous connections, leave this parameter blank.
  • Description. Comment describing the shared folder. This comment is visible to users who have enabled the Details view in My Network Places.

Scripting Steps

Listing 11.37 contains a script that modifies the properties of the FinanceShare shared folder 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.

    To limit data retrieval to a specified share, a Where clause is included restricting the returned folders to those with the name FinanceShare. Without the Where clause, all the shared folders would be returned, and each shared folder would then have its properties modified.

  4. For each shared folder in the collection, use the SetShareInfo method to set the MaximumAllowed and Description properties. The SetShareInfo method is passed two parameters:
    • 50 Indicating that the share supports a maximum of 50 simultaneous connections.
    • Public share for HR administrators and members of the Finance Group Description displayed to users accessing the share through My Network Places.

Listing 11.37   Modifying Network Share Properties

1 2 3 4 5 6 7 8 9 10 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colShares = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Share WHERE Name = 'FinanceShare'") For Each objShare in colShares     errReturn = objShare.SetShareInfo(50, _         "Public share for HR administrators and the Finance Group.") Next Wscript.Echo errReturn

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