I need to set access control to a folder
my code is
Private Sub cmdApplyRestrictions_Click(sender As Object, e As EventArgs) Handles cmdApplyRestrictions.Click
Dim myDirectoryInfo As New DirectoryInfo(txtFolder.Text)
Dim myDirectorySecurity As DirectorySecurity = myDirectoryInfo.GetAccessControl()
Dim User As String = System.Environment.UserDomainName + "\" + cmbUser.SelectedItem.ToString()
myDirectorySecurity.AddAccessRule(New FileSystemAccessRule(User, FileSystemRights.Read, AccessControlType.Deny))
myDirectoryInfo.SetAccessControl(myDirectorySecurity)
MessageBox.Show("Permissions Altered Successfully")
End Sub
the line
myDirectoryInfo.SetAccessControl(myDirectorySecurity)
is giving exception as
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
I am logged in as a user with administrative rights but not administrator itself i need to block access to all users including the logged in user as well as all user including administrator
later when my program ends, i will to restore the permissions
One more requirement is that i wish to grant access to this folder one external program