2个回答
展开全部
解决方法:在C#中如何实现使文件夹成为共享或Web共享
Web共享
==============
DirectoryEntry ent = new DirectoryEntry("IIS://oh35d-install1/w3svc");
DirectoryEntry entchild = new DirectoryEntry();
entchild = ent.Children.Add("5","IIsWebServer");
entchild.CommitChanges();
entchild.Properties["ServerBindings"].Value = ":123:";
entchild.Properties["ServerState"].Value = 2;
entchild.Properties["ServerComment"].Value = "TESTSITE";
entchild.CommitChanges();
DirectoryEntry vdir = entchild.Children.Add("ROOT","IIsWebVirtualDir");
vdir.CommitChanges();
vdir.Properties["AppIsolated"].Value = 2;
vdir.Properties["Path"].Value = @"C:\Inetpub\wwwroot";
vdir.Properties["AuthFlags"].Value = 5;
vdir.Properties["DirBrowseFlags"].Value = 1073741886;
vdir.Properties["AccessFlags"].Value = 513;
vdir.CommitChanges();
entchild.CommitChanges();
ent.CommitChanges();
Web共享
==============
DirectoryEntry ent = new DirectoryEntry("IIS://oh35d-install1/w3svc");
DirectoryEntry entchild = new DirectoryEntry();
entchild = ent.Children.Add("5","IIsWebServer");
entchild.CommitChanges();
entchild.Properties["ServerBindings"].Value = ":123:";
entchild.Properties["ServerState"].Value = 2;
entchild.Properties["ServerComment"].Value = "TESTSITE";
entchild.CommitChanges();
DirectoryEntry vdir = entchild.Children.Add("ROOT","IIsWebVirtualDir");
vdir.CommitChanges();
vdir.Properties["AppIsolated"].Value = 2;
vdir.Properties["Path"].Value = @"C:\Inetpub\wwwroot";
vdir.Properties["AuthFlags"].Value = 5;
vdir.Properties["DirBrowseFlags"].Value = 1073741886;
vdir.Properties["AccessFlags"].Value = 513;
vdir.CommitChanges();
entchild.CommitChanges();
ent.CommitChanges();
参考资料: http://www.msproject.cn/Document/Window_ShareFolder.html
展开全部
List<FileSystemRights>
ret
=
new
List<FileSystemRights>();
DirectorySecurity
dirSec
=
Directory.GetAccessControl(@"c:\test",
AccessControlSections.All);
AuthorizationRuleCollection
rules
=
dirSec.GetAccessRules(true,
true,
typeof(System.Security.Principal.NTAccount));
foreach
(FileSystemAccessRule
rule
in
rules)
{
ret.Add(rule.FileSystemRights);
}
ret里面就是各个帐号对该目录的访问权限,你在里面判断一下就知道了,格式是这样的:
ReadData
|
WriteData
|
AppendData
|
ReadExtendedAttributes
|
WriteExtendedAttributes
|
ExecuteFile
|
DeleteSubdirectoriesAndFiles
|
ReadAttributes
|
WriteAttributes
|
Delete
|
ReadPermissions
|
ChangePermissions
|
TakeOwnership
|
Synchronize
ret
=
new
List<FileSystemRights>();
DirectorySecurity
dirSec
=
Directory.GetAccessControl(@"c:\test",
AccessControlSections.All);
AuthorizationRuleCollection
rules
=
dirSec.GetAccessRules(true,
true,
typeof(System.Security.Principal.NTAccount));
foreach
(FileSystemAccessRule
rule
in
rules)
{
ret.Add(rule.FileSystemRights);
}
ret里面就是各个帐号对该目录的访问权限,你在里面判断一下就知道了,格式是这样的:
ReadData
|
WriteData
|
AppendData
|
ReadExtendedAttributes
|
WriteExtendedAttributes
|
ExecuteFile
|
DeleteSubdirectoriesAndFiles
|
ReadAttributes
|
WriteAttributes
|
Delete
|
ReadPermissions
|
ChangePermissions
|
TakeOwnership
|
Synchronize
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询