急的发抖:如何建立共享目录?

zhouhui123 2005-12-26 11:43:55
急死了,请教如何建立共享目录,请提供点代码
...全文
202 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ytfrdfiw 2006-04-27
  • 打赏
  • 举报
回复
太强,五颗星都来了。
aa3000 2005-12-28
  • 打赏
  • 举报
回复
我也顶一下呀
yayaniuniu502 2005-12-28
  • 打赏
  • 举报
回复
好强,帮顶一个
snakebite2008 2005-12-26
  • 打赏
  • 举报
回复
为什么微软的大部分例程都是VB的?
Kudeet 2005-12-26
  • 打赏
  • 举报
回复
共享/删除共享除了直接调用标准的Win32API函数NetShareAdd和NetShareDel

回复人: acptvb(微软全球技术中心 VB技术支持)
您还可以通过ADSI方式的IADsFileShare对象设置共享,如下例(VB):

Sub foo()

Dim comp As IADsComputer
Dim serv As IADsService
Dim fserv As IADsContainer
Dim share As IADsFileShare
Dim shareNew As IADsFileShare
Dim v As Variant

' Replace DOMAIN, SERVER & SHARE with the appropriate
' domain, server and share names

Set share = GetObject("WinNT://DOMAIN/SERVER/lanmanserver/SHARE")

v = share.Path ' Gets directory path on server

Set share = nothing

' Replace DOMAIN & SERVER with the appropriate domain and server names

Set fserv = GetObject("WinNT://DOMAIN/SERVER/lanmanserver")

' Enumerate existing shares

For Each share In fserv
v = share.Class
v = share.ADsPath
v = share.HostComputer
v = share.Path
Next share

' Create share in fileservice container

Set shareNew = fserv.Create("fileshare", "newshare")
shareNew.Path = "C:\"
shareNew.SetInfo ' Commit new share

' Delete share

fserv.Delete "fileshare", "newshare"

' Fails since share is gone

shareNew.GetInfo

End Sub

请参考下面的例子:

Q169398 HOWTO: Manipulate File Shares with ADSI (VB Sample)
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q169398

Q234234 How to Manage File Shares Using ADSI
http://support.microsoft.com/support/kb/articles/q234/2/34.asp


然后,您可以利用ADsSecurity.dll 来获取文件夹的security descriptor,通过IADsAccessControlList的AddAce方法为文件夹的AccessControlList添加用户权限。

您可以在以下链接获得相关代码及ADsSecurity.dll的有关信息。
HOWTO: Use Visual Basic and ADsSecurity.dll to Properly Order ACEs in an ACL
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q269159

HOWTO: Use ADsSecurity.dll to Add an Access Control Entry to an NTFS Folder
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q279682

需要注意的是,如果您的文件夹包含子目录,文件夹的权限不会自动的向下传播,您需要递归的设置所有子目录的权限属性。
相关代码及详细信息请参考:
Q266461 HOWTO:Set Automatic Inheritance of File/Folder Permissions- ADSI
http://support.microsoft.com/support/kb/articles/q266/4/61.asp
菜牛 2005-12-26
  • 打赏
  • 举报
回复
NetShareAdd

The NetShareAdd function shares a server resource.


NetShareAdd Sample (Windows 95/98/Me)

The following code sample demonstrates how to share a resource on the local computer with a call to the NetShareAdd function.


The code sample specifies the share_info_50 structure and no password on the share. The sample also allocates and frees the memory required for the information buffer.

#include <stdio.h>
#include <windows.h>
#include <svrapi.h>

int main(int argc, char FAR * argv[])
{
char FAR * pszServerName = NULL;
short nLevel = 50;
struct share_info_50* pBuf = NULL;
unsigned short cbBuffer;
NET_API_STATUS nStatus;
//
// ServerName can be NULL to indicate the local computer.
//
if ((argc < 3) || (argc > 4))
{
printf("Usage: %s [\\\\ServerName] ShareName SharePath\n", argv[0]);
exit(1);
}

if (argc == 4)
pszServerName = argv[1];
//
// Allocate the memory required to specify a
// share_info_50 structure.
//
cbBuffer = sizeof(struct share_info_50);
pBuf = malloc(cbBuffer);

if (pBuf == NULL)
printf("No memory\n");
//
// Assign values to the share_info_50 structure.
//
strcpy(pBuf->shi50_netname, argv[argc-2]);
pBuf->shi50_type = STYPE_DISKTREE;
pBuf->shi50_flags = SHI50F_FULL;
pBuf->shi50_remark = NULL;
pBuf->shi50_path = argv[argc-1];
pBuf->shi50_rw_password[0] = '\0'; // No password
pBuf->shi50_ro_password[0] = '\0'; // No password
//
// Call the NetShareAdd function
// specifying information level 50.
//
nStatus = NetShareAdd(pszServerName,
nLevel,
(char FAR *)pBuf,
cbBuffer);
//
// Display the result of the function call.
//
if (nStatus == NERR_Success)
printf("Share added successfully\n");
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
free(pBuf);

return 0;
}

wangk 2005-12-26
  • 打赏
  • 举报
回复
来晚了。
补充:使用NetShareAdd在98和nt系列(NT、2000、Xp)是要包含不同的头文件。
98:
#include <Svrapi.h>
#pragma comment(lib,"Svrapi.lib")

nt:
#include <Lm.h>
#pragma comment(lib,"Netapi32.lib")

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧