我想将可移动驱动器(USB)的权限级别更改为每个人只读,并完全控制Windows的当前用户。 互联网上有许多教程可用于更改文件,文件夹,目录,权限级别。 但我找不到任何更改USB权限级别的来源。 任何人都可以帮我解决这个问题吗?
我们可以通过使用Windows的GUI来更改或添加新用户,我们可以使用手动方法更改权限并在Windows中添加新权限。 但是我们怎样才能在C#.NET中做到这一点?
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?
最满意答案
我只是使用此链接解决了我的问题,并包括此命名空间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);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);更多推荐
发布评论