RhGetProcessToken() public static method

public static RhGetProcessToken ( Int32 InProcessId, IntPtr &OutToken ) : void
InProcessId System.Int32
OutToken System.IntPtr
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Returns the <see cref="WindowsIdentity"/> of the user the target process belongs to.
        /// You need <c>PROCESS_QUERY_INFORMATION</c> access to the target.
        /// </summary>
        /// <param name="InTargetPID">An accessible target process ID.</param>
        /// <returns>The identity of the target owner.</returns>
        /// <exception cref="AccessViolationException">
        /// The given process is not accessible.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The given process does not exist.
        /// </exception>
        public static WindowsIdentity GetProcessIdentity(Int32 InTargetPID)
        {
            IntPtr          hToken;
            WindowsIdentity Result;

            NativeAPI.RhGetProcessToken(InTargetPID, out hToken);

            try
            {
                Result = new WindowsIdentity(hToken);
            }
            finally
            {
                NativeAPI.CloseHandle(hToken);
            }

            return(Result);
        }