Recipe 8.23. Creating and Deleting Shares


Problem

You want to create or delete a shared folder.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. In the left pane, browse to the folder you want to start or stop sharing.

  3. Right-click folder and select Sharing and Security.

  4. To stop sharing the folder, select Do not share this folder.

  5. To share the folder, select Share this folder. Enter the Share name, enter a description for the share in the Comment field, and specify the User limit.

  6. Click OK to close the dialog box.

Using a command-line interface

The following command creates a share called Perl Libs:

> net share "Perl Libs"=d:\perl\lib /unlimited /remark:"Core Perl modules"

The /unlimited option means that an unlimited number of users can access the share simultaneously. You can limit the number of simultaneous users by using the /users:<Number> option instead.

This command deletes a share:

> net share "Perl Libs" /delete

Using VBScript
' This code creates a share. ' ------ SCRIPT CONFIGURATION ------ strComputer   = "." strPath       = "d:\perl\lib" strName       = "Perl Libs" intType       = 0 ' share a disk drive resource intMaxAllowed = 10  strDescr      = "Core Perl modules" ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objShare = objWMI.Get("Win32_Share") intRC = objShare.Create(strPath, strName, intType, intMaxAllowed, strDescr) if intRC <> 0 then    WScript.Echo "Error creating share: " & intRC else    WScript.Echo "Successfully created share" end if ' This code deletes a share. ' ------ SCRIPT CONFIGURATION ------ strComputer   = "." strName       = "Perl Libs" ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objShare = objWMI.Get("Win32_Share.Name='" & strName & "'") intRC = objShare.Delete if intRC <> 0 then    WScript.Echo "Error deleted share: " & intRC else    WScript.Echo "Successfully deleted share" end if

Discussion

After you create a share, you need to modify the access control list (ACL) to include the users and groups that can access the contents of the share (see Recipe 8.25 for more on this).

If you want to create a hidden share, simply append $ to the end of the share name. The only thing different about a hidden share is that it won't be directly viewable when listing the shared folders on a system. Hiding shares is kind of like hiding files (Recipe 8.12) it is up to the application to display them or not. So hidden shares are not truly hidden, but they will not be visible to the casual user.

See Also

MS KB 324267, "HOW TO: Share Files and Folders over the Network in a Windows Server 2003 Domain Environment"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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