使用vb.net获取文件/文件夹权限

时间:2012-12-15 14:52:24

标签: windows vb.net file permissions

我可以使用给定的代码设置文件/文件夹限制。

Imports System.Security.AccessControl

Dim FolderPath As String = "C:\TestingFolder" '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.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FolderInfo.SetAccessControl(FolderAcl)

我的目标是使用代码设置权限,只有我的应用程序才能更改对文件/文件夹的读/写访问权限。除了我的vb.net程序,没有人可以更改权限。 我的目标是编写一个安全应用程序,它将要求密码访问程序,程序将能够授予用户访问权限(读/写/修改)。

0 个答案:

没有答案