且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用vb.net设置Windows文件夹权限

更新时间:2022-11-28 11:38:17

I 用Google搜索 [ ^ ]这个适合你。我猜你现在在中国吗?
I googled[^] this for you. I guess you're in China then ?


Dim FolderPath As String = "C:\Test" 'Specify the folder here
Dim UserAccount As String = "mydomain\Someuser" 'Specify the user here

Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
Dim FolderAcl As New DirectorySecurity
FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.ReadAndExecute Or FileSystemRights.Write, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
'FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FolderInfo.SetAccessControl(FolderAcl)