Kill all excels in process..VB.net
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As IntPtr) As IntPtr
- Dim xlapp As New excel.Application
- .
- .
- Dim processId1 As IntPtr
- GetWindowThreadProcessId(xlapp.Hwnd, processId1)
- Dim excelProcess1 As Process = Process.GetProcessById(processId1.ToInt32())
- Debug.WriteLine(processId1)
- excelProcess1.Kill()
- xlapp = Nothing
- GC.Collect()
- GC.WaitForPendingFinalizers()