2010-09-27 61 views

回答

1

如果你的意思是NTFS權限,然後看看下面的代碼:

/* 
* Set Modify permission on D:\MyWebSite and all children 
*/ 

string path = @"D:\MyWebSite"; 
string userID = "BOB"; 

FileSystemRights rights = FileSystemRights.Modify; 
InheritanceFlags inheritanceflags = 
      InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; 

DirectorySecurity acls = Directory.GetAccessControl(path); 
FileSystemAccessRule acl = 
    new FileSystemAccessRule(
      new NTAccount(userID), 
      rights, 
      inheritanceFlags, 
      PropagationFlags.None, 
      AccessControlType.Allow); 
acls.AddAccessRule(acl); 
Directory.SetAccessControl(path, acls); 

欲瞭解更多信息請參閱:

DirectoryInfo.SetAccessControl Method (MSDN)

DirectorySecurity Class (MSDN)

FileSystemAccessRule Class (MSDN)

您還可以使用icacls.exe

icacls.exe d:\MyWebSite /grant bob:(CI)(OI)M

+0

感謝您的答覆。我得到了我的答案。 – Sandy 2010-09-30 06:16:01

+0

@Sandy - 有禮貌地贊成或標記爲正確的答案,幫助你解決問題,否則,StackOverflow上的友善人士會覺得不太願意在將來爲你提供幫助。 – Kev 2010-09-30 08:49:00

+0

你能告訴我如何做upvote? – Sandy 2010-09-30 09:59:19