0

I want to change permission level of the removable drive(USB) to be readonly for everyone and full control to the current user of the windows. There are many tutorials available on internet for changing of file, folder, directory,permission level. But i could not find any source to change a permission level of a USB. Can anyone help me to sort this out?

We can change or add new user, we can change permissions and add new permission in windows using manual method mean by using GUI of windows. But how can we do this in C#.NET?

Shhzdmrz
  • 45
  • 10

1 Answers1

0

I just solve my question just using this Link and including this namespace System.Security.Principal.

DirectorySecurity sec = Directory.GetAccessControl(path);
// Using this instead of the "Everyone" string means we work on non-English systems. 
 SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, sec);
Community
  • 1
  • 1
Shhzdmrz
  • 45
  • 10