ProblemYou want to create or delete a shared folder. SolutionUsing a graphical user interface
Using a command-line interfaceThe 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 DiscussionAfter 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 AlsoMS KB 324267, "HOW TO: Share Files and Folders over the Network in a Windows Server 2003 Domain Environment" |