我们可以更改驱动器/可移动驱动器权限级别吗?(Can we change a drive/removable drive permission level?)

编程入门 行业动态 更新时间:2024-10-28 04:23:26
我们可以更改驱动器/可移动驱动器权限级别吗?(Can we change a drive/removable drive permission level?)

我想将可移动驱动器(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);

更多推荐

本文发布于:2023-08-05 20:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动器   我们可以   权限   级别   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!