2000下磁盘共享的问题(50分)

  • 主题发起人 主题发起人 BlackHawk
  • 开始时间 开始时间
B

BlackHawk

Unregistered / Unconfirmed
GUEST, unregistred user!
我的朋友是计算机教师,上计算机课的时候经常将不同的磁盘共享给学生,现在的计算机硬盘大,非常麻烦,影响讲课速度,所以像编一个小程序实现,所以让我代他问一下各位(其实是问我,我不会),怎样在2000下共享磁盘或指定的目录?
 
找到的一篇文章,希望对你有用。<br><br>怎样在Delphi程序中设置共享文件夹?我试过很多种方法,但均失败。急请高手指点。 <br>1、设置HKEY_LOCAL_MACHINE<br><br>2、<br><br>SVRAPI.DLL里有<br><br>NetShareAdd;<br><br>NetShareDel;<br><br>NetShareGetInfo;<br><br>NetShareSetInfo;<br><br>NetShareAdd<br><br>The NetShareAdd function shares a server resource.<br><br>Security Requirements<br><br>Only members of the Administrators or Account Operators local group or those with Communication, Print, or Server operator group membership can successfully execute the NetShareAdd function. The Print operator can add only Printer queues. The Communication operator can add only communication-device queues.<br><br>Windows NT/2000: The parameter order is as follows.<br><br>NET_API_STATUS NetShareAdd(<br><br>LPWSTR servername,<br><br>DWORD level,<br><br>LPBYTE buf,<br><br>LPDWORD parm_err<br><br>);<br><br>Windows 95/98: You must specify the size of the information buffer, in bytes, using the cbBuffer parameter. The Windows NT/Windows 2000 parm_err parameter is not available on this platform. Therefore, the parameter list is as follows.<br><br>extern API_FUNCTION<br><br>NetShareAdd(<br><br>const char FAR * pszServer,<br><br>short sLevel,<br><br>const char FAR * pbBuffer,<br><br>unsigned short cbBuffer<br><br>);<br><br>Parameters<br><br>servername<br><br>[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying the name of the remote server on which the function is to execute. The string must begin with /. If this parameter is NULL, the local computer is used.<br><br>level<br><br>[in] Specifies the information level of the data. This parameter can be one of the following values.<br><br>Windows NT/2000: The following levels are valid. Value Meaning<br><br>2 Specifies information about the shared resource, including name of the resource, type and permissions, and number of connections. The buf parameter points to a SHARE_INFO_2 structure.<br><br>502 Specifies information about the shared resource, including name of the resource, type and permissions, number of connections, and other pertinent information. The buf parameter points to a SHARE_INFO_502 structure.<br><br> <br><br> <br><br>Windows 95/98: The following level is valid. Value Meaning<br><br>50 Specifies information about the shared resource, including the name and type of the resource, a comment associated with the resource, and passwords. The pbBuffer parameter points to a share_info_50 structure. Note that the string you specify in the shi50_path member must contain only uppercase characters. If the path contains lowercase characters, calls to NetShareAdd can fail with NERR_UnknownDevDir or ERROR_BAD_NET_NAME.<br><br> <br><br> <br><br>buf<br><br>[in] Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter.<br><br>parm_err<br><br>[out] Pointer to a DWORD value that receives the index of the first member of the share information structure that causes the ERROR_INVALID_PARAMETER error. If this parameter is NULL, the index is not returned on error. For more information, see the NetShareSetInfo function.<br><br>Return Values<br><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 error codes.<br><br>Value Meaning<br><br>ERROR_ACCESS_DENIED The user does not have access to the requested information.<br><br>ERROR_INVALID_LEVEL The value specified for the level parameter is invalid.<br><br>ERROR_INVALID_NAME The character or file system name is invalid.<br><br>ERROR_INVALID_PARAMETER The specified parameter is invalid.<br><br>NERR_DuplicateShare The share name is already in use on this server.<br><br>NERR_RedirectedPath The operation is invalid for a redirected resource. The specified device name is assigned to a shared resource.<br><br>NERR_UnknownDevDir The device or directory does not exist.<br><br> <br><br>Remarks<br><br>Windows 95/98: See the NetShareAdd Sample (Windows 95/98) topic to view 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 network resource using a call to the NetShareAdd function. The code sample fills in the members of the SHARE_INFO_2 structure and calls NetShareAdd, specifying information level 2.<br><br>#define UNICODE<br><br>#include &lt;windows.h&gt;<br><br>#include &lt;stdio.h&gt;<br><br>#include &lt;lm.h&gt;<br><br>void wmain( int argc, TCHAR *argv[ ])<br><br>{<br><br>NET_API_STATUS res;<br><br>SHARE_INFO_2 p;<br><br>DWORD parm_err = 0;<br><br>if(argc&lt;2)<br><br>printf("Usage: NetShareAdd server");<br><br>else<br><br>{<br><br>//<br><br>// Fill in the SHARE_INFO_2 structure.<br><br>//<br><br>p.shi2_netname = TEXT("TESTSHARE");<br><br>p.shi2_type = STYPE_DISKTREE; // disk drive<br><br>p.shi2_remark = TEXT("TESTSHARE to test NetShareAdd");<br><br>p.shi2_permissions = 0;<br><br>p.shi2_max_uses = 4;<br><br>p.shi2_current_uses = 0;<br><br>p.shi2_path = TEXT("C:/");<br><br>p.shi2_passwd = NULL; // no password<br><br>//<br><br>// Call the NetShareAdd function,<br><br>// specifying level 2.<br><br>//<br><br>res=NetShareAdd(argv[1], 2, (LPBYTE) &amp;p, &amp;parm_err);<br><br>//<br><br>// If the call succeeds, inform the user.<br><br>//<br><br>if(res==0)<br><br>printf("Share created.");<br><br> <br><br>// Otherwise, print an error,<br><br>// and identify the parameter in error.<br><br>//<br><br>else<br><br>printf("Error: %u=%u", res, parm_err);<br><br>}<br><br>return;<br><br>}<br><br>If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare.<br><br>Requirements<br><br>Windows NT/2000: Requires Windows NT 3.1 or later.<br><br>Windows 95/98: Requires Windows 95 or later.<br><br>Header: Declared in Lmshare.h (Windows NT/2000) or Svrapi.h (Windows 95/98); include Lm.h (Windows NT/2000).<br><br>Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows 95/98)
 
如果是手工设置的共享文件夹的参数在这里:HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/lanmanserver/Shares<br>修改注册表:HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Network/LanMan/<br>添加一值为Flags,258。即可实现磁盘完全共享。<br>编程也无非是利用注册表的相关API。 &nbsp;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
890
DelphiTeacher的专栏
D
D
回复
0
查看
858
DelphiTeacher的专栏
D
后退
顶部