本文介绍了如何让用户拥有访问驱动程序文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在编写了一个驱动程序,但是当我在另一台计算机上安装驱动程序总是失败时,我遇到了一个非常麻烦的问题,并且我调试了程序,发现安装软件无权编写或在drivers文件夹中进行任何更改,现在有谁可以更改用户的权限.请帮助.

i now wrote a driver,but i encounter a really troublesome problem , when i installed the driver on other computer is always failed ,and i debug the program found out that the install software didn''t have the right to write or do any changes in the drivers folder ,is there anyone who now how to change the user''s right.please help.

推荐答案

private static void FixAccess(FileSystemSecurity sec)
{
    string currentUser = WindowsIdentity.GetCurrent().Name;
    sec.AddAccessRule(new FileSystemAccessRule
    (currentUser, FileSystemRights.FullControl, AccessControlType.Allow));
}


我还清除了所有现有规则,以期避免冲突.


I also clear all the existing rules in the hope that it will avoid conflicts.

foreach (FileSystemAccessRule fsar in sec.GetAccessRules
    (true, true, typeof(System.Security.Principal.NTAccount)).OfType<filesystemaccessrule />().ToArray())
{
    sec.RemoveAccessRuleAll(fsar);
}


不幸的是,大多数情况在一开始都是失败的,我找不到原因.我认为解决方案是修复文件的所有权.


Unfortunately, most of this was failing at the beginning and I could not find out why. I thought the solution was to fix the ownership of the file.

private static void FixOwner(FileSystemSecurity sec)
{
    var sid = sec.GetOwner(typeof(SecurityIdentifier));
    string currentUser = WindowsIdentity.GetCurrent().Name;
    var ntAccount = new NTAccount(currentUser);
    sec.SetOwner(ntAccount);
}


这篇关于如何让用户拥有访问驱动程序文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:22