Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Creating shared folders on the local computer is easy. In Windows Explorer, simply right-click a folder, select Sharing and Security, enter the desired share name, and click OK. If you prefer to use the command line, you can use the net share command to accomplish the same task.
Sharing folders on remote computers is a different story; neither Windows Explorer nor net share allows you to share out a folder on another computer. However, you can use WMI and the Win32_Share class to create a shared folder on remote computers as well as on the local computer.
To create a shared folder using WMI, you need to connect to the Win32_Share class and then call the Create method. The Create method requires you to specify the five parameters shown inTable 11.12.
Table 11.12 Shared Folder Parameters
Parameter | Description |
---|---|
Path | Local path to the folder being shared. This folder must already exist or the Create method fails. |
Name | Share name used to access the folder over the network. To create a hidden share, append a $ at the end of the name (for example, MyShare$). A hidden share is not visible to users browsing in Network Neighborhood but remains available to anyone who knows that the share exists. |
Type | Indicates the type of network share. This is typically one of two values: 0 Standard network file share. These shared folders can be viewed by anyone on the network. However, you can use share permissions or NTFS permissions to limit access to the contents of the share. 2147483648 Administrative share. For example, the Administrative share Admin$ resolves to the Windows folder on a computer. Only users with Administrative credentials can connect to these shared folders. |
MaximumAllowed | Maximum number of users permitted to connect to the share at one time. If this parameter is left blank, an unlimited number of simultaneous connections to the share are permitted. |
Description | Optional description displayed when users view the share in Network Neighborhood. |
Values returned from calling the Create method are shown in Table 11.13.
Table 11.13 Network Share Return Values
Value | Description |
---|---|
0 | The operation completed successfully. |
2 | The operation could not be completed because access was denied. |
8 | The operation could not be completed because of an unknown problem. |
9 | The operation could not be completed because an invalid name was specified. |
10 | The operation could not be completed because an invalid level was specified. |
21 | The operation could not be completed because an invalid parameter was specified. |
22 | The operation could not be completed because a share by this name already exists. |
23 | The operation could not be completed because this is a redirected path. |
24 | The operation could not be completed because the specified folder could not be found. |
25 | The operation could not be completed because the specified server could not be found. |
Other | The operation could not be completed. |
Listing 11.33 contains a script that creates a shared folder on a computer. To carry out this task, the script must perform the following steps:
Listing 11.33 Creating Shared Folders
|
|
Send us your feedback | « Previous | Next » |