Beispiel #1
0
 public void Kill()
 {
     using (var p = Process.GetProcessById((int)processId.GetValue()))
     {
         IntPtr h = IntPtr.Zero;
         try
         {
             if (!NativeMethods.DuplicateHandle(p.Handle, handle, NativeMethods.GetCurrentProcess(), out h, 0, false, DuplicateOptions.DUPLICATE_CLOSE_SOURCE))
             {
                 throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
             }
         }
         finally
         {
             if (h != IntPtr.Zero)
             {
                 NativeMethods.CloseHandle(h);
             }
         }
     }
 }