Click here to Skip to main content
15,887,892 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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?
Posted
Comments
Richard MacCutchan 4-Oct-15 8:37am    
I think you can only do that through Security Policy settings.
Shahzad Mirza 4-Oct-15 9:13am    
Do you think FileSystemAuditRule Class could help me for doing this?

1 solution

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

I just used below code to change permissions on the root folder (e.g. "G:\")

C#
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);
 
Share this answer
 
Comments
BillWoodruff 4-Oct-15 22:45pm    
+5 good answer !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900