Created On:  29 August 2012
 
When using Active Data in a Workbench .Net script, Workbench opens Excel automatically when running the script. Therefore If a script fails or ends unexpectedly then Excel may not be closed correctly and can remain running in task manager. This can cause issues when re-running the script as the Active Data cannot be correctly opened.

If manually closing Excel is not a practical option (for example if scripts are run unattended) then the best approach is to have some code in your script which will check if Excel is running prior to calling the Active Data and if it is, then close it down.

The code below contains a function called IsProcessRunning() which checks if Excel is running and if it is, then kills it. The function should be called from the Public Sub Main() with “Excel” passed in as the process name.

NB. The function “IsProcessRunning()” accepts the string parameter which is the process name

Imports System.Diagnostics

Public Module Main
       Dim _desktop As Desktop = Agent.Desktop

       Public Sub Main()   
       IsProcessRunning("EXCEL")   
       End Sub

Public Function IsProcessRunning(name As String) As Boolean
    'here we're going to get a list of all running processes on
    'the computer

    For Each clsProcess As Process In Process.GetProcesses()
        If clsProcess.ProcessName.StartsWith(name) Then

            clsProcess.Kill()
            Return True
        End If
    Next
    'process not found, return false
    Return False

End Function
End Module

Incident #2588657