Ejemplo n.º 1
0
        /// <summary>
        /// Duplicates a given process handle owned by a given process into a given destination process
        /// </summary>
        /// <param name="owner">A handle to the process that owns the handle</param>
        /// <param name="sourceHandle">The process handle to be duplicated</param>
        /// <param name="desiredRights">The desired process rights of the new handle</param>
        /// <param name="inherit">Whether the new handle is inheritable</param>
        /// <param name="options">The duplication options to use when duplicating</param>
        /// <param name="destination">The process that should recieve the handle duplicate</param>
        /// <returns>The newly duplicated handle</returns>
        /// <exception cref="Win32Exception">On windows api error</exception>
        public static SafeProcessHandle DuplicateProcessHandle(SafeProcessHandle owner, IntPtr sourceHandle,
                                                               ProcessRights desiredRights, Boolean inherit, DuplicationOptions options, SafeProcessHandle destination)
        {
            IntPtr handle = Duplicate(owner, sourceHandle,
                                      (UInt32)desiredRights, inherit, options, destination);

            return(new SafeProcessHandle(handle, true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Duplicates a given process handle owned by a given process into this process
        /// </summary>
        /// <param name="owner">A handle to the process that owns the handle</param>
        /// <param name="sourceHandle">The process handle to be duplicated</param>
        /// <param name="desiredRights">The desired process rights of the new handle</param>
        /// <param name="inherit">Whether the new handle is inheritable</param>
        /// <param name="options">The duplication options to use when duplicating</param>
        /// <returns>The newly duplicated handle</returns>
        /// <exception cref="Win32Exception">On windows api error</exception>
        public static SafeProcessHandle DuplicateProcessHandle(SafeProcessHandle owner, IntPtr sourceHandle,
                                                               ProcessRights desiredRights, Boolean inherit, DuplicationOptions options)
        {
            var process = Process.GetCurrentProcess();

            return(DuplicateProcessHandle(owner, sourceHandle, desiredRights,
                                          inherit, options, process.Handle));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns whether this handle holds at least given process rights
        /// </summary>
        /// <param name="rights">The minimum access rights required</param>
        /// <returns>A boolean indicating whether this handle holds at minimum given access rights</returns>
        public Boolean HasRights(ProcessRights rights)
        {
            if (Type != HandleType.Process)
            {
                throw new InvalidOperationException("Can only check process rights on a process handle");
            }

            return(HasRights((uint)rights));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Opens a handle with given access rights to a process with given process id
        /// </summary>
        /// <param name="id">The id of the process to be opened</param>
        /// <param name="desiredRights">The desired access rights to the process</param>
        /// <returns>The new handle to the process</returns>
        /// <exception cref="Win32Exception">On Windows API error</exception>
        public static SafeProcessHandle OpenProcess(Int32 id, ProcessRights desiredRights)
        {
            IntPtr handle = Kernel32.OpenProcess(desiredRights, false, Convert.ToUInt32(id));

            if (handle.IsNullPtr())
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not open handle to process");
            }

            return(new SafeProcessHandle(handle, true));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessAuditRule"/> class.
 /// </summary>
 /// <param name="identity">The identity.</param>
 /// <param name="processRights">The process rights.</param>
 /// <param name="type">The type.</param>
 public ProcessAuditRule(string identity, ProcessRights processRights, AuditFlags type)
     : this(new NTAccount(identity), processRights, type)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessAuditRule"/> class.
 /// </summary>
 /// <param name="identity">The identity.</param>
 /// <param name="processRights">The process rights.</param>
 /// <param name="type">The type.</param>
 public ProcessAuditRule(IdentityReference identity, ProcessRights processRights, AuditFlags type)
     : base(identity, (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Ejemplo n.º 7
0
 public ProcessAccessRule(string identity, ProcessRights processRights, AccessControlType type)
     : this(new NTAccount(identity), processRights, type)
 {
 }
Ejemplo n.º 8
0
 public ProcessAccessRule(IdentityReference identity, ProcessRights processRights, AccessControlType type)
     : base(identity, (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessAuditRule"/> class.
 /// </summary>
 /// <param name="identity">The identity.</param>
 /// <param name="processRights">The process rights.</param>
 /// <param name="type">The type.</param>
 public ProcessAuditRule(string identity, ProcessRights processRights, AuditFlags type)
     : this(new NTAccount(identity), processRights, type)
 {
 }
Ejemplo n.º 10
0
 public ProcessAuditRule(IdentityReference identity, ProcessRights processRights, AuditFlags flags)
     : this(identity, (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, flags)
 {
 }
Ejemplo n.º 11
0
 public ProcessAccessRule(string identity, ProcessRights processRights, AccessControlType type)
     : this(new NTAccount(identity), (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Ejemplo n.º 12
0
 public ProcessAccessRule(IdentityReference identity, ProcessRights processRights, AccessControlType type)
     : this(identity, (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Ejemplo n.º 13
0
 public ProcessAccessRule(string identity, ProcessRights processRights, AccessControlType type)
     : this(new NTAccount(identity), processRights, type)
 {
 }
Ejemplo n.º 14
0
 public static extern IntPtr OpenProcess(ProcessRights dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
Ejemplo n.º 15
0
 public static extern IntPtr OpenProcess([In] ProcessRights desiredRights, [In] Boolean inheritHandle,
                                         [In] UInt32 processId);
Ejemplo n.º 16
0
 /// <summary>
 /// Opens a process with given process id
 /// </summary>
 /// <param name="id">The id of the process to be opened</param>
 /// <param name="desiredRights">The desired access rights to the process</param>
 /// <returns>The newly opened process</returns>
 /// <exception cref="Win32Exception">On Windows API error</exception>
 public static Process Open(Int32 id, ProcessRights desiredRights)
 {
     return(new Process(Win32.Handle.OpenProcess(id, desiredRights)));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessAuditRule"/> class.
 /// </summary>
 /// <param name="identity">The identity.</param>
 /// <param name="processRights">The process rights.</param>
 /// <param name="type">The type.</param>
 public ProcessAuditRule(IdentityReference identity, ProcessRights processRights, AuditFlags type)
     : base(identity, (int)processRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }