如何共享硬盘?(20分)

  • 主题发起人 主题发起人 chen___ye
  • 开始时间 开始时间
C

chen___ye

Unregistered / Unconfirmed
GUEST, unregistred user!
如何共享硬盘?紧急!
 
用NetShareAdd
 
能再详细些么?
 
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>&nbsp; LPWSTR servername, <br>&nbsp; DWORD level, &nbsp; &nbsp; &nbsp; <br>&nbsp; LPBYTE buf, &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; LPDWORD parm_err &nbsp; <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>&nbsp;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>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. &nbsp;<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. &nbsp;<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 &lt;windows.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;lm.h&gt;<br><br>void wmain( int argc, TCHAR *argv[ ])<br>{<br>&nbsp; &nbsp;NET_API_STATUS res;<br>&nbsp; &nbsp;SHARE_INFO_2 p;<br>&nbsp; &nbsp;DWORD parm_err = 0;<br><br>&nbsp; &nbsp;if(argc&lt;2)<br>&nbsp; &nbsp; &nbsp; printf("Usage: NetShareAdd server/n");<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; // Fill in the SHARE_INFO_2 structure.<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; p.shi2_netname = TEXT("TESTSHARE"); &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; p.shi2_type = STYPE_DISKTREE; // disk drive<br>&nbsp; &nbsp; &nbsp; p.shi2_remark = TEXT("TESTSHARE to test NetShareAdd");<br>&nbsp; &nbsp; &nbsp; p.shi2_permissions = 0; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; p.shi2_max_uses = 4;<br>&nbsp; &nbsp; &nbsp; p.shi2_current_uses = 0; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; p.shi2_path = TEXT("C://");<br>&nbsp; &nbsp; &nbsp; p.shi2_passwd = NULL; // no password<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; // Call the NetShareAdd function,<br>&nbsp; &nbsp; &nbsp; // &nbsp;specifying level 2.<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; res=NetShareAdd(argv[1], 2, (LPBYTE) &amp;p, &amp;parm_err);<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; // If the call succeeds, inform the user.<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; if(res==0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("Share created./n");<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; // Otherwise, print an error,<br>&nbsp; &nbsp; &nbsp; // &nbsp;and identify the parameter in error.<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("Error: %u/tparmerr=%u/n", res, parm_err);<br>&nbsp; &nbsp;}<br>&nbsp; &nbsp;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>&nbsp; Windows NT/2000: Requires Windows NT 3.1 or later.<br>&nbsp; Windows 95/98: Requires Windows 95 or later.<br>&nbsp; Header: Declared in Lmshare.h (Windows NT/2000) or Svrapi.h (Windows<br>95/98); include Lm.h (Windows NT/2000).<br>&nbsp; Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows<br>95/98).<br>
 
不会巴,这么难看,有中文的么?,我要求的系统是win98
 
我当初用的也是在win98下,用这个没问题,我一下子没法给你找到范例,我在公司,代码在家里
 
那好,我等你,真是太感谢你这位大虾了
 
明天星期六休息,上不了网,我从写了一下。<br>98最好用Share_INFO_2<br>NT最好用SHARE_INFO_502 <br>unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; <br><br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br><br>&nbsp; end;<br><br>&nbsp; Share_INFO_2= record<br>&nbsp; &nbsp; shi2_netname:PWideChar; <br>&nbsp; &nbsp; shi2_type:DWORD;<br>&nbsp; &nbsp; shi2_remark:LPTSTR;<br>&nbsp; &nbsp; shi2_permissions:DWORD;<br>&nbsp; &nbsp; shi2_max_uses:DWORD;<br>&nbsp; &nbsp; shi2_current_uses:DWORD;<br>&nbsp; &nbsp; shi2_path:PWideChar;<br>&nbsp; &nbsp; shi2_passwd:LPTSTR;<br>&nbsp; &nbsp; end;<br>&nbsp; PShare_INFO_2 = ^Share_INFO_2;<br>&nbsp; LPShare_INFO_2 = ^Share_INFO_2;<br><br>&nbsp; SHARE_INFO_502 =record<br>&nbsp; &nbsp; &nbsp; shi502_netname: &nbsp; &nbsp; &nbsp;PCHAR;<br>&nbsp; &nbsp; &nbsp; shi502_type: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD;<br>&nbsp; &nbsp; &nbsp; shi502_remark: &nbsp; &nbsp; &nbsp; &nbsp;PCHAR;<br>&nbsp; &nbsp; &nbsp; shi502_permissions: &nbsp;DWORD;<br>&nbsp; &nbsp; &nbsp; shi502_max_uses: &nbsp; &nbsp; &nbsp;DWORD;<br>&nbsp; &nbsp; &nbsp; shi502_current_uses: &nbsp;DWORD;<br>&nbsp; &nbsp; &nbsp; shi502_path: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PCHAR;<br>&nbsp; &nbsp; &nbsp; shi502_passwd: &nbsp; &nbsp; &nbsp; &nbsp;PCHAR;<br>&nbsp; &nbsp; &nbsp; shi502_reserved: &nbsp; &nbsp; &nbsp;DWORD;<br>&nbsp; &nbsp; &nbsp; shi502_security_descriptor: PSECURITY_DESCRIPTOR;<br>&nbsp; end;<br>&nbsp; PSHARE_INFO_502= ^SHARE_INFO_502;<br>&nbsp; LPSHARE_INFO_502=^SHARE_INFO_502;<br><br><br>const<br><br>STYPE_DISKTREE &nbsp; &nbsp; &nbsp;= $0001;<br>ACCESS_READ &nbsp; &nbsp; &nbsp; &nbsp;= $0001;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; F:Cardinal;<br>&nbsp; function NetShareAdd(<br>&nbsp; &nbsp; &nbsp; &nbsp; Server : PwideChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; level : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; Buf : Pointer;<br>&nbsp; &nbsp; &nbsp; &nbsp; var Parm_Err : DWORD):Cardinal;stdcall; external 'netapi32.dll' name 'NetShareAdd';<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>buf:Pointer;<br>UserInf:Share_INFO_2;<br>UserInf502:Share_INFO_502;<br>err:dWord;<br>begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; err:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; f:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_netname:='test';<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_type:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_remark:='';<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_permissions:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_max_uses:= 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_current_uses:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_path:='C:/';<br>&nbsp; &nbsp; &nbsp; &nbsp; UserInf.shi2_passwd:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetMem(Buf ,sizeof(UserInf));<br>&nbsp; &nbsp; &nbsp; &nbsp; F:=NetSHAREAdd(nil,2,@UserInf,err);<br>&nbsp; &nbsp; &nbsp; &nbsp; FreeMem(Buf);<br><br><br>end;<br><br>end. <br>
 
为什么在win98下运行时出现"连接到不存在的输出NETAPI32.dll:netshareAdd错误呢"?,赐教
 
我这里没问题呀。你的netapi32.dll是不是有问题呀
 
不知道怎么回事,我这里调试了几台,都不行(win98),赐教!(昨天有事,耽误了)
 
查一下你集子里有没有NETAPI32.dll,如果有的话,铐到你的编的程序目录下。如果没有那肯定<br>是不能运行的
 
还是不行。<br>“连接到不存在的输出NETAPI32.dll:netshareAdd” 这个错误
 
直接修改注册表就可以了
 
怎么修改,具体一点行不?
 
with TRegistry.Create do begin<br>RootKey :=HKEY_LOCAL_MACHINE;<br>if OpenKey('/SOFTWARE/Microsoft/Windows/CurrentVersion/Network/LanMan/C',True) then begin<br>WriteInteger('Flags',258);WriteInteger('Type',0);WriteString('Path','C:/');WriteString('Remark','c');CloseKey<br>end;<br>查看一下Lanman下面的东西,就都明白了<br>
 
WK<br>到我的主页http://lovejingtao.126.com程序设计里面有代码下的。
 
谢谢各位的回答,还想问一下,如何删掉右击菜单中共享选项,或者让它不使能
 
后退
顶部