示例#1
0
        private void MakeHandleNoninheritable(ref SafeFileHandle handler, IntPtr processHandle)
        {
            // Create noninheritable read handle and close the inheritable read handle.
            IntPtr handleClone;

            if (!ConsoleApi.DuplicateHandle(
                    processHandle,
                    handler.DangerousGetHandle(),
                    processHandle,
                    out handleClone,
                    0,
                    false,
                    Constants.DUPLICATE_SAME_ACCESS))
            {
                throw InteropException.CreateWithInnerHResultException("Couldn't duplicate the handle.");
            }

            SafeFileHandle toRelease = handler;

            handler = new SafeFileHandle(handleClone, true);
            toRelease.Dispose();
        }