Results 1 to 2 of 2

Thread: [RESOLVED] Obtaining the process ID, VbScript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Resolved [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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    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:
    1. Declare Function GetCurrentProcessId Lib "kernel32" () As Long

    and call it from vbScript
    VB Code:
    1. DTSGlobalVariables("PID").Value =  Excel_Application.Run("GetCurrentProcessId")

    Enjoy Killing Process !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width