Monday, June 03, 2013

How to Kill Excel Ghost Process in SSIS using VB.NET

Here is the simple method to kill Excel Ghost process which is running behind scene while running SSIS package. Here is a small method to kill Excel process if we know the excel caption or excel title we want to close.
Code snippet of the method to kill Excel process
Private Sub KillExcellProcess(ByVal excelCaption As String)
Dim proc As System.Diagnostics.Process
For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
If (proc.MainWindowTitle = excelCaption) Then
proc.Kill()
End If
Next
End Sub

Use this method in SSIS script task to kill the Excel Ghost process by calling this method in your code
 
Dim xlApp As Excel.Application
Dim xlBook As Excel.WorkbookClass
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp.Visible = False
xlApp.DisplayAlerts = False
' Once done with excel stuff and when you want
' to kill excel use the below lines of code
Dim sCaption As String
sCaption = xlApp.Caption
KillExcellProcess(sCaption)
 
Hope this helps!!

3 comments:

  1. Hi Nagasai,

    This helps but even if excel has caption, proc.MainWindowTitle is blank always which is not killing specific excel instant.

    could you please help?

    Thanks
    Trupti

    ReplyDelete
    Replies
    1. Hi Trupti,
      Try this, http://www.inagasai.com/2013/06/how-to-kill-specific-excel-ghost.html

      Delete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai.

    ReplyDelete