You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 regels
1004 B

  1. // <copyright file="ProcessHandle.cs" company="Nick Lowe">
  2. // Copyright © Nick Lowe 2009
  3. // </copyright>
  4. // <author>Nick Lowe</author>
  5. // <email>nick@int-r.net</email>
  6. // <url>http://processprivileges.codeplex.com/</url>
  7. namespace ProcessPrivileges
  8. {
  9. using System;
  10. using System.ComponentModel;
  11. using System.Runtime.ConstrainedExecution;
  12. using System.Runtime.InteropServices;
  13. using Microsoft.Win32.SafeHandles;
  14. internal sealed class ProcessHandle : SafeHandleZeroOrMinusOneIsInvalid
  15. {
  16. internal ProcessHandle(IntPtr processHandle, bool ownsHandle)
  17. : base(ownsHandle)
  18. {
  19. handle = processHandle;
  20. }
  21. [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
  22. protected override bool ReleaseHandle()
  23. {
  24. if (!NativeMethods.CloseHandle(handle))
  25. {
  26. throw new Win32Exception(Marshal.GetLastWin32Error());
  27. }
  28. return true;
  29. }
  30. }
  31. }