在Windows 95/98中该API的使用与NT有所不同:<br>你必须使用第四个参数指明信息块的大小(字节),而非NT中的错误代码。<br>另外,sLevel 也只有 50 可用,2、502只能为NT使用。<br>NET_API_STATUS NetShareAdd(<br> const char FAR * pszServer, <br> short sLevel, <br> const char FAR * pbBuffer, <br> unsigned short cbBuffer <br>);<br><br>示例:<br>#include <stdio.h><br>#include <windows.h> <br>#include <svrapi.h><br><br>int main(int argc, char FAR * argv[])<br>{<br> char FAR * pszServerName = NULL;<br> short nLevel = 50;<br> struct share_info_50* pBuf = NULL;<br> unsigned short cbBuffer;<br> NET_API_STATUS nStatus;<br> //<br> // ServerName can be NULL to indicate the local computer.<br> //<br> if ((argc < 3) || (argc > 4))<br> {<br> printf("Usage: %s [////ServerName] ShareName SharePath/n", argv[0]);<br> exit(1);<br> }<br><br> if (argc == 4)<br> pszServerName = argv[1];<br> //<br> // Allocate the memory required to specify a <br> // share_info_50 structure.<br> //<br> cbBuffer = sizeof(struct share_info_50);<br> pBuf = malloc(cbBuffer);<br><br> if (pBuf == NULL)<br> printf("No memory/n");<br> //<br> // Assign values to the share_info_50 structure.<br> //<br> strcpy(pBuf->shi50_netname, argv[argc-2]);<br> pBuf->shi50_type = STYPE_DISKTREE;<br> pBuf->shi50_flags = SHI50F_FULL;<br> pBuf->shi50_remark = NULL;<br> pBuf->shi50_path = argv[argc-1];<br> pBuf->shi50_rw_password[0] = '/0'; // No password<br> pBuf->shi50_ro_password[0] = '/0'; // No password<br> //<br> // Call the NetShareAdd function<br> // specifying information level 50.<br> //<br> nStatus = NetShareAdd(pszServerName,<br> nLevel,<br> (char FAR *)pBuf,<br> cbBuffer);<br> //<br> // Display the result of the function call.<br> //<br> if (nStatus == NERR_Success)<br> printf("Share added successfully/n");<br> else<br> fprintf(stderr, "A system error has occurred: %d/n", nStatus);<br> //<br> // Free the allocated memory.<br> //<br> if (pBuf != NULL)<br> free(pBuf);<br><br> return 0;<br>}<br><br>-----------------------------------------<br>给分吧!<br>