WIndows file/ folder permission using vb.net

Deadly 提交于 2019-12-24 07:49:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!