在Win95中,netshareadd怎么用?(200分)

  • 主题发起人 主题发起人 luming
  • 开始时间 开始时间
L

luming

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