简体   繁体   中英

Can we change a drive/removable drive permission level?

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM