问题
I can set file/ folder restriction using the given code.
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)
My aim is to set the permission using the code in a way that only my application can change the read/write access to the file/folder. No one can change the permission except my vb.net program. My goal is to write a security application which will ask password to access the program, and the program will be able to grant access(read/write/modify) to the user.
来源:https://stackoverflow.com/questions/13893232/windows-file-folder-permission-using-vb-net