NetShareAdd<br>The NetShareAdd function shares a server resource.<br><br>Security Requirements<br>Only members of the Administrators or Account Operators local group or<br>those with Communication, Print, or Server operator group membership can<br>successfully execute the NetShareAdd function. The Print operator can<br>add only Printer queues. The Communication operator can add only<br>communication-device queues.<br><br>Windows NT/2000: The parameter order is as follows.<br><br>NET_API_STATUS NetShareAdd(<br> LPWSTR servername, <br> DWORD level, <br> LPBYTE buf, <br> LPDWORD parm_err <br>);<br>Windows 95/98: You must specify the size of the information buffer, in<br>bytes, using the cbBuffer parameter. The Windows NT/Windows 2000<br>parm_err parameter is not available on this platform. Therefore, the<br>parameter list is as follows. <br><br>extern API_FUNCTION<br> NetShareAdd(<br> const char FAR * pszServer, <br> short sLevel, <br> const char FAR * pbBuffer, <br> unsigned short cbBuffer <br>);<br>Parameters<br>servername <br>[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98)<br>string specifying the name of the remote server on which the function is<br>to execute. The string must begin with //. If this parameter is NULL,<br>the local computer is used. <br>level <br>[in] Specifies the information level of the data. This parameter can be<br>one of the following values. <br>Windows NT/2000: The following levels are valid. Value Meaning <br>2 Specifies information about the shared resource, including name of the<br>resource, type and permissions, and number of connections. The buf<br>parameter points to a SHARE_INFO_2 structure. <br>502 Specifies information about the shared resource, including name of<br>the resource, type and permissions, number of connections, and other<br>pertinent information. The buf parameter points to a SHARE_INFO_502<br>structure. <br><br><br><br>Windows 95/98: The following level is valid. Value Meaning <br>50 Specifies information about the shared resource, including the name<br>and type of the resource, a comment associated with the resource, and<br>passwords. The pbBuffer parameter points to a share_info_50 structure.<br>Note that the string you specify in the shi50_path member must contain<br>only uppercase characters. If the path contains lowercase characters,<br>calls to NetShareAdd can fail with NERR_UnknownDevDir or<br>ERROR_BAD_NET_NAME. <br><br><br><br>buf <br>[in] Pointer to the buffer that specifies the data. The format of this<br>data depends on the value of the level parameter. <br>parm_err <br>[out] Pointer to a DWORD value that receives the index of the first<br>member of the share information structure that causes the<br>ERROR_INVALID_PARAMETER error. If this parameter is NULL, the index is<br>not returned on error. For more information, see the NetShareSetInfo<br>function. <br>Return Values<br>If the function succeeds, the return value is NERR_Success.<br><br>If the function fails, the return value can be one of the following<br>error codes.<br><br>Value Meaning <br>ERROR_ACCESS_DENIED The user does not have access to the requested<br>information. <br>ERROR_INVALID_LEVEL The value specified for the level parameter is<br>invalid. <br>ERROR_INVALID_NAME The character or file system name is invalid. <br>ERROR_INVALID_PARAMETER The specified parameter is invalid. <br>NERR_DuplicateShare The share name is already in use on this server. <br>NERR_RedirectedPath The operation is invalid for a redirected resource.<br>The specified device name is assigned to a shared resource. <br>NERR_UnknownDevDir The device or directory does not exist. <br><br><br>Remarks<br>Windows 95/98: See the NetShareAdd Sample (Windows 95/98) topic to view<br>a code sample that demonstrates how to use the NetShareAdd function.<br><br>Windows NT/2000: The following code sample demonstrates how to share a<br>network resource using a call to the NetShareAdd function. The code<br>sample fills in the members of the SHARE_INFO_2 structure and calls<br>NetShareAdd, specifying information level 2.<br><br>#define UNICODE<br>#include <windows.h><br>#include <stdio.h><br>#include <lm.h><br><br>void wmain( int argc, TCHAR *argv[ ])<br>{<br> NET_API_STATUS res;<br> SHARE_INFO_2 p;<br> DWORD parm_err = 0;<br><br> if(argc<2)<br> printf("Usage: NetShareAdd server/n");<br> else<br> {<br> //<br> // Fill in the SHARE_INFO_2 structure.<br> //<br> p.shi2_netname = TEXT("TESTSHARE"); <br> p.shi2_type = STYPE_DISKTREE; // disk drive<br> p.shi2_remark = TEXT("TESTSHARE to test NetShareAdd");<br> p.shi2_permissions = 0; <br> p.shi2_max_uses = 4;<br> p.shi2_current_uses = 0; <br> p.shi2_path = TEXT("C://");<br> p.shi2_passwd = NULL; // no password<br> //<br> // Call the NetShareAdd function,<br> // specifying level 2.<br> //<br> res=NetShareAdd(argv[1], 2, (LPBYTE) &p, &parm_err);<br> //<br> // If the call succeeds, inform the user.<br> //<br> if(res==0)<br> printf("Share created./n");<br> <br> // Otherwise, print an error,<br> // and identify the parameter in error.<br> //<br> else<br> printf("Error: %u/tparmerr=%u/n", res, parm_err);<br> }<br> return;<br>}<br>If you are programming for Active Directory, you may be able to call<br>certain Active Directory Service Interface (ADSI) methods to achieve the<br>same functionality you can achieve by calling the network management<br>share functions. For more information, see IADsFileShare.<br><br>Requirements <br> Windows NT/2000: Requires Windows NT 3.1 or later.<br> Windows 95/98: Requires Windows 95 or later.<br> Header: Declared in Lmshare.h (Windows NT/2000) or Svrapi.h (Windows<br>95/98); include Lm.h (Windows NT/2000).<br> Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows<br>95/98).<br>