简体   繁体   English

我们可以更改驱动器/可移动驱动器的许可级别吗?

[英]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. 我想将可移动驱动器(USB)的权限级别更改为所有人只读,并完全控制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. 但是我找不到任何来源来更改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. 我们可以更改或添加新用户,也可以在Windows中使用手动方法更改权限并在Windows中添加新权限。 But how can we do this in C#.NET? 但是我们如何在C#.NET中做到这一点?

I just solve my question just using this Link and including this namespace System.Security.Principal. 我只是使用此Link并包括此命名空间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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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