微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法在C#中修改进程DACL

我有遗留的C代码更改进程DACL并尝试使用.NET 3.5中的托管代码类.我在网上找到了有人创建了一个SetAclOnServices类的代码,该类扩展了服务的NativeObjectSecurity类.我认为我可以实现这一点,只需将ResourceType.Service更改为ResourceType.KernelObject,但是当我调用GetAccessControl时,它会失败并显示File Not Found错误.

解决方法

圣诞节快乐.
public class ProcessSecurity : NativeObjectSecurity
{
    public ProcessSecurity(SafeHandle processHandle)
        : base(false,ResourceType.KernelObject,processHandle,AccessControlSections.Access)
    {

    }

    public void AddAccessRule(ProcessAccessRule rule)
    {
        base.AddAccessRule(rule);
    }

    // this is not a full impl- it only supports writing DACL changes
    public void SaveChanges(SafeHandle processHandle)
    {
        Persist(processHandle,AccessControlSections.Access);
    }

    public override Type AccessRightType
    {
        get { return typeof(ProcessAccessRights); }
    }

    public override AccessRule AccessRuleFactory(System.Security.Principal.IdentityReference identityReference,int accessMask,bool isInherited,InheritanceFlags inheritanceFlags,PropagationFlags propagationFlags,AccessControlType type)
    {
        return new ProcessAccessRule(identityReference,(ProcessAccessRights)accessMask,isInherited,inheritanceFlags,propagationFlags,type);
    }

    public override Type AccessRuleType
    {
        get { return typeof(ProcessAccessRule); }
    }

    public override AuditRule AuditRuleFactory(System.Security.Principal.IdentityReference identityReference,AuditFlags flags)
    {
        throw new NotImplementedException();
    }

    public override Type AuditRuleType
    {
        get { throw new NotImplementedException(); }
    }
}

public class ProcessAccessRule : AccessRule
{
    public ProcessAccessRule(IdentityReference identityReference,ProcessAccessRights accessMask,AccessControlType type)
        : base(identityReference,(int)accessMask,type)
    {
    }

    public ProcessAccessRights ProcessAccessRights { get { return (ProcessAccessRights)AccessMask; } }
}

[Flags]
public enum ProcessAccessRights
{
    STANDARD_RIGHTS_required = (0x000F0000),DELETE = (0x00010000),// required to delete the object. 
    READ_CONTROL = (0x00020000),// required to read information in the security descriptor for the object,not including the information in the SACL. To read or write the SACL,you must request the ACCESS_SYstem_Security access right. For more information,see SACL Access Right. 
    WRITE_DAC = (0x00040000),// required to modify the DACL in the security descriptor for the object. 
    WRITE_OWNER = (0x00080000),// required to change the owner in the security descriptor for the object. 

    PROCESS_ALL_ACCESS = STANDARD_RIGHTS_required | SYNCHRONIZE | 0xFFF,//All possible access rights for a process object.
    PROCESS_CREATE_PROCESS = (0x0080),// required to create a process. 
    PROCESS_CREATE_THREAD = (0x0002),// required to create a thread. 
    PROCESS_DUP_HANDLE = (0x0040),// required to duplicate a handle using DuplicateHandle. 
    PROCESS_QUERY_informatION = (0x0400),// required to retrieve certain information about a process,such as its token,exit code,and priority class (see OpenProcesstoken,GetExitCodeProcess,GetPriorityClass,and IsProcessInJob). 
    PROCESS_QUERY_LIMITED_informatION = (0x1000),PROCESS_SET_informatION = (0x0200),// required to set certain information about a process,such as its priority class (see SetPriorityClass). 
    PROCESS_SET_QUOTA = (0x0100),// required to set memory limits using SetProcessWorkingSetSize. 
    PROCESS_SUSPEND_RESUME = (0x0800),// required to suspend or resume a process. 
    PROCESS_TERMINATE = (0x0001),// required to terminate a process using TerminateProcess. 
    PROCESS_VM_OPERATION = (0x0008),// required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory). 
    PROCESS_VM_READ = (0x0010),// required to read memory in a process using ReadProcessMemory. 
    PROCESS_VM_WRITE = (0x0020),// required to write to memory in a process using WriteProcessMemory. 
    SYNCHRONIZE = (0x00100000),// required to wait for the process to terminate using the wait functions. 
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


原文地址:http://msdn.microsoft.com/en-us/magazine/cc163791.aspx 原文发布日期: 9/19/2005 原文已经被 Microsoft 删除了,收集过程中发现很多文章图都不全,那是因为原文的图都不全,所以特收集完整全文。 目录 前言 CLR启动程序
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采纳和使用,它的确提供了很多的优势也解决了很多的问题,但是我们也知道也并不是银弹,提供优势的同时它也给我们的开发人员和团队也带来了很多的挑战。 为了迎接或者采用这些新技术,开发团队需要更加注重一些流程或工具的使用,这样才能更好的适应这些新技术所
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下PLINQ中的分区。上一篇介绍了并行编程,这边详细介绍一下并行编程中的分区和自定义分区。 先做个假设,假设我们有一个200Mb的文本文件需要读取,怎么样才能做到最优的速度呢?对,很显然就是拆分,把文本文件拆分成很多个小文件,充分利用我们计算机中
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Microsoft为了利用这个硬件特性,于是在Visual Studio 2010 和 .NET Framework 4的发布及以上版本中,添加了并行编程这个新特性,我想它以后势必会改变我们的开发方式。 在以前或者说现在,我们在并行开发的时候可
c语言输入成绩怎么判断等级
字符型数据在内存中的存储形式是什么
c语言怎么求字符串的长度并输出
c语言函数的三种调用方式是什么
c语言中保留两位小数怎么表示
double的输入格式符是什么