[RESOLVED] Obtaining the process ID, VbScript
Hi guys,
I need to get the process ID of the Excel Application that I just lunched with VbScript. I need it for security reason, in case the macro failed, Excel process is still running. I'm running this script on SQL Server, in a DTS Package. So if the macro fail, another script will terminate the Excel Process.
I am able to kill all Excel process at once, but I need to only kill the Excel process where the macro failed
Here is the code:
Function Main()
Dim Excel_Application
Set Excel_Application = CreateObject("Excel.Application")
/////Need to get the process ID right Here
Excel_Application.Workbooks.Open("c:\que.xls")
Excel_Application.Run ("Main") 'Name of the macro to run
Excel_Application.DisplayAlerts=False
Excel_Application.Quit
Set Excel_Application = Nothing
Main = DTSTaskExecResult_Success
End Function
Thanks
Re: Obtaining the process ID, VbScript
not an easy one, but finally made it
needed to put this function on a module of my Excel File
VB Code:
Declare Function GetCurrentProcessId Lib "kernel32" () As Long
and call it from vbScript
VB Code:
DTSGlobalVariables("PID").Value = Excel_Application.Run("GetCurrentProcessId")
Enjoy Killing Process !!!