继承我的代码
Dim FolderPath As String = "C:/folder"
Dim UserAccount As String = "(DESKTOP-T34R8TH\Users)"
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
Dim FolderAcl As New DirectorySecurity
FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
FolderInfo.SetAccessControl(FolderAcl)
没有任何反应。我希望该文件夹具有写入权限。
答案 0 :(得分:0)
您无法将新的DirectorySecurity对象添加到该文件夹。您必须检索现有的并修改它。
所以不要使用
Dim FolderAcl As New DirectorySecurity
你应该使用
Dim FolderAcl As DirectorySecurity = FolderInfo.GetAccessControl()
有关综合示例,请参阅MS文档here。