本文介绍了设置NTFS权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试设置NTFS权限以及创建共享.份额和份额许可工作正常,只是安全性"不是标签中的属性"标签.
用户所有人"
这个代码也可以在W7,Vista和XP中使用吗?
我没有想到这个代码. .
Hi,
I am trying to set NTFS permisions as well as create a share. the share and share permisions are working ok just not the "security " tab in the folder propperties.
the user "everyone " is in there just nothing ticked.
also is this code usable in W7, Vista, and XP?
I did not think of this code.. I thank lots of google.
public string CreateShare(string path, string name, string description, string maxallowed)
{
try
{
Directory.CreateDirectory(path);
NTAccount account = new NTAccount("Everyone");
SecurityIdentifier sid = (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));
byte[] sidArray = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidArray, 0);
FileSystemAccessRule everyOne = new FileSystemAccessRule(account, FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow);
DirectorySecurity dirSecurity = new DirectorySecurity(path, AccessControlSections.Group);
dirSecurity.AddAccessRule(everyOne);
Directory.SetAccessControl(path, dirSecurity);
ManagementObject Trustee = new ManagementClass(new ManagementPath("Win32_Trustee"), null);
Trustee["Domain"] = "contoso";
Trustee["Name"] = "johndoe";
Trustee["SID"] = sidArray;
ManagementObject AdminACE = new ManagementClass(new ManagementPath("Win32_Ace"), null);
AdminACE["AccessMask"] = 2032127;
AdminACE["AceFlags"] = 3;
AdminACE["AceType"] = 0;
AdminACE["Trustee"] = Trustee;
ManagementObject secDescriptor = new ManagementClass(new ManagementPath("Win32_SecurityDescriptor"), null);
secDescriptor["ControlFlags"] = 4; //SE_DACL_PRESENT
secDescriptor["DACL"] = new object[] { AdminACE };
ManagementClass managementClass = new ManagementClass("Win32_Share");
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
inParams["Description"] = description;
inParams["Name"] = name;
inParams["Path"] = path;
inParams["Type"] = 0x0; // Disk Drive
inParams["access"] = secDescriptor;
ManagementBaseObject outParams;
outParams = managementClass.InvokeMethod("Create", inParams, null);
if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception(path);
}
}
catch (Exception e)
{
return e.Message;
}
return "OK";
}
推荐答案
这篇关于设置NTFS权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!