Connecting Tech Pros Worldwide Help | Site Map

Obtain a Process ID

Frank DeLuccia
Guest
 
Posts: n/a
#1: Nov 22 '05
Hello All,

Hope eveyone is having a better morning than me today. Anyway, I know
the .NET framework has classes to obtain process ID's of processes running
in the task manager. My question is; Does .NET have anything in it's bag of
tricks to give me the process ID of an instance I create through code?

Example:

Dim objExcel as Excel.Application

objExcel = New Excel.Application <----- I want to know the process ID
right after I create this instance.

Is there anyway I can get that info? Any guidance would be greatly
appreciated.

-Thanks,
Frank


Bob Phillips
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Obtain a Process ID


Hi Frank,

Don't know about .NET, but this function gets a process id. Perhaps you can
build into .NET

Function ProcID() As Long
Dim hwnd As Long
Dim idProc As Long
hwnd = FindWindow(vbNullString, "Microsoft Excel")
Call GetWindowThreadProcessId(hwnd, idProc)
ProcID = idProc

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote in
message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=blue]
> Hello All,
>
> Hope eveyone is having a better morning than me today. Anyway, I know
> the .NET framework has classes to obtain process ID's of processes running
> in the task manager. My question is; Does .NET have anything in it's bag[/color]
of[color=blue]
> tricks to give me the process ID of an instance I create through code?
>
> Example:
>
> Dim objExcel as Excel.Application
>
> objExcel = New Excel.Application <----- I want to know the process ID
> right after I create this instance.
>
> Is there anyway I can get that info? Any guidance would be greatly
> appreciated.
>
> -Thanks,
> Frank
>
>[/color]


Bob Phillips
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Obtain a Process ID


Hi Frank,

Don't know about .NET, but this function gets a process id. Perhaps you can
build into .NET

Function ProcID() As Long
Dim hwnd As Long
Dim idProc As Long
hwnd = FindWindow(vbNullString, "Microsoft Excel")
Call GetWindowThreadProcessId(hwnd, idProc)
ProcID = idProc

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote in
message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=blue]
> Hello All,
>
> Hope eveyone is having a better morning than me today. Anyway, I know
> the .NET framework has classes to obtain process ID's of processes running
> in the task manager. My question is; Does .NET have anything in it's bag[/color]
of[color=blue]
> tricks to give me the process ID of an instance I create through code?
>
> Example:
>
> Dim objExcel as Excel.Application
>
> objExcel = New Excel.Application <----- I want to know the process ID
> right after I create this instance.
>
> Is there anyway I can get that info? Any guidance would be greatly
> appreciated.
>
> -Thanks,
> Frank
>
>[/color]


Frank DeLuccia
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Obtain a Process ID


Bob,

Thanks for the hint but the Excel visible property is set to false b/c
this is an automated process without interaction, there could be multiple
instances of excel running, and I need the process ID of the instance being
created at runtime. The thought is if there is an error in that instance
running, I can kill that process using the ID while leaving the other
instances alone.

Thanks for your time,
Frank

"Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi Frank,
>
> Don't know about .NET, but this function gets a process id. Perhaps you[/color]
can[color=blue]
> build into .NET
>
> Function ProcID() As Long
> Dim hwnd As Long
> Dim idProc As Long
> hwnd = FindWindow(vbNullString, "Microsoft Excel")
> Call GetWindowThreadProcessId(hwnd, idProc)
> ProcID = idProc
>
> End Function
>
>
> --
>
> HTH
>
> Bob Phillips
> ... looking out across Poole Harbour to the Purbecks
> (remove nothere from the email address if mailing direct)
>
> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote in
> message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=green]
> > Hello All,
> >
> > Hope eveyone is having a better morning than me today. Anyway, I[/color][/color]
know[color=blue][color=green]
> > the .NET framework has classes to obtain process ID's of processes[/color][/color]
running[color=blue][color=green]
> > in the task manager. My question is; Does .NET have anything in it's[/color][/color]
bag[color=blue]
> of[color=green]
> > tricks to give me the process ID of an instance I create through code?
> >
> > Example:
> >
> > Dim objExcel as Excel.Application
> >
> > objExcel = New Excel.Application <----- I want to know the process ID
> > right after I create this instance.
> >
> > Is there anyway I can get that info? Any guidance would be greatly
> > appreciated.
> >
> > -Thanks,
> > Frank
> >
> >[/color]
>
>[/color]


Frank DeLuccia
Guest
 
Posts: n/a
#5: Nov 22 '05

re: Obtain a Process ID


Bob,

Thanks for the hint but the Excel visible property is set to false b/c
this is an automated process without interaction, there could be multiple
instances of excel running, and I need the process ID of the instance being
created at runtime. The thought is if there is an error in that instance
running, I can kill that process using the ID while leaving the other
instances alone.

Thanks for your time,
Frank

"Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi Frank,
>
> Don't know about .NET, but this function gets a process id. Perhaps you[/color]
can[color=blue]
> build into .NET
>
> Function ProcID() As Long
> Dim hwnd As Long
> Dim idProc As Long
> hwnd = FindWindow(vbNullString, "Microsoft Excel")
> Call GetWindowThreadProcessId(hwnd, idProc)
> ProcID = idProc
>
> End Function
>
>
> --
>
> HTH
>
> Bob Phillips
> ... looking out across Poole Harbour to the Purbecks
> (remove nothere from the email address if mailing direct)
>
> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote in
> message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=green]
> > Hello All,
> >
> > Hope eveyone is having a better morning than me today. Anyway, I[/color][/color]
know[color=blue][color=green]
> > the .NET framework has classes to obtain process ID's of processes[/color][/color]
running[color=blue][color=green]
> > in the task manager. My question is; Does .NET have anything in it's[/color][/color]
bag[color=blue]
> of[color=green]
> > tricks to give me the process ID of an instance I create through code?
> >
> > Example:
> >
> > Dim objExcel as Excel.Application
> >
> > objExcel = New Excel.Application <----- I want to know the process ID
> > right after I create this instance.
> >
> > Is there anyway I can get that info? Any guidance would be greatly
> > appreciated.
> >
> > -Thanks,
> > Frank
> >
> >[/color]
>
>[/color]


Jake Marx
Guest
 
Posts: n/a
#6: Nov 22 '05

re: Obtain a Process ID


Hi Frank,

I think you could still use Bob's suggestion. When you create the instance
of Excel, just check the value of the application's Hwnd property. Then
pass that value to the GetWindowThreadProcessId function to get the PID.

In your case:

Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long

Sub Test()
Dim objExcel As Excel.Application
Dim lPID As Long

Set objExcel = New Excel.Application
GetWindowThreadProcessId objExcel.hwnd, lPID
Debug.Print "PID: " & CStr(lPID)
objExcel.Quit
Set objExcel = Nothing
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Frank DeLuccia wrote:[color=blue]
> Bob,
>
> Thanks for the hint but the Excel visible property is set to
> false b/c this is an automated process without interaction, there
> could be multiple instances of excel running, and I need the process
> ID of the instance being created at runtime. The thought is if there
> is an error in that instance running, I can kill that process using
> the ID while leaving the other instances alone.
>
> Thanks for your time,
> Frank
>
> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
> news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=green]
>> Hi Frank,
>>
>> Don't know about .NET, but this function gets a process id. Perhaps
>> you can build into .NET
>>
>> Function ProcID() As Long
>> Dim hwnd As Long
>> Dim idProc As Long
>> hwnd = FindWindow(vbNullString, "Microsoft Excel")
>> Call GetWindowThreadProcessId(hwnd, idProc)
>> ProcID = idProc
>>
>> End Function
>>
>>
>> --
>>
>> HTH
>>
>> Bob Phillips
>> ... looking out across Poole Harbour to the Purbecks
>> (remove nothere from the email address if mailing direct)
>>
>> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote
>> in message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=darkred]
>>> Hello All,
>>>
>>> Hope eveyone is having a better morning than me today. Anyway,
>>> I know the .NET framework has classes to obtain process ID's of
>>> processes running in the task manager. My question is; Does .NET
>>> have anything in it's bag of tricks to give me the process ID of an
>>> instance I create through code?
>>>
>>> Example:
>>>
>>> Dim objExcel as Excel.Application
>>>
>>> objExcel = New Excel.Application <----- I want to know the
>>> process ID right after I create this instance.
>>>
>>> Is there anyway I can get that info? Any guidance would be greatly
>>> appreciated.
>>>
>>> -Thanks,
>>> Frank[/color][/color][/color]

Jake Marx
Guest
 
Posts: n/a
#7: Nov 22 '05

re: Obtain a Process ID


Hi Frank,

I think you could still use Bob's suggestion. When you create the instance
of Excel, just check the value of the application's Hwnd property. Then
pass that value to the GetWindowThreadProcessId function to get the PID.

In your case:

Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long

Sub Test()
Dim objExcel As Excel.Application
Dim lPID As Long

Set objExcel = New Excel.Application
GetWindowThreadProcessId objExcel.hwnd, lPID
Debug.Print "PID: " & CStr(lPID)
objExcel.Quit
Set objExcel = Nothing
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Frank DeLuccia wrote:[color=blue]
> Bob,
>
> Thanks for the hint but the Excel visible property is set to
> false b/c this is an automated process without interaction, there
> could be multiple instances of excel running, and I need the process
> ID of the instance being created at runtime. The thought is if there
> is an error in that instance running, I can kill that process using
> the ID while leaving the other instances alone.
>
> Thanks for your time,
> Frank
>
> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
> news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=green]
>> Hi Frank,
>>
>> Don't know about .NET, but this function gets a process id. Perhaps
>> you can build into .NET
>>
>> Function ProcID() As Long
>> Dim hwnd As Long
>> Dim idProc As Long
>> hwnd = FindWindow(vbNullString, "Microsoft Excel")
>> Call GetWindowThreadProcessId(hwnd, idProc)
>> ProcID = idProc
>>
>> End Function
>>
>>
>> --
>>
>> HTH
>>
>> Bob Phillips
>> ... looking out across Poole Harbour to the Purbecks
>> (remove nothere from the email address if mailing direct)
>>
>> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote
>> in message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...[color=darkred]
>>> Hello All,
>>>
>>> Hope eveyone is having a better morning than me today. Anyway,
>>> I know the .NET framework has classes to obtain process ID's of
>>> processes running in the task manager. My question is; Does .NET
>>> have anything in it's bag of tricks to give me the process ID of an
>>> instance I create through code?
>>>
>>> Example:
>>>
>>> Dim objExcel as Excel.Application
>>>
>>> objExcel = New Excel.Application <----- I want to know the
>>> process ID right after I create this instance.
>>>
>>> Is there anyway I can get that info? Any guidance would be greatly
>>> appreciated.
>>>
>>> -Thanks,
>>> Frank[/color][/color][/color]

Frank DeLuccia
Guest
 
Posts: n/a
#8: Nov 22 '05

re: Obtain a Process ID


Thanks, Guys, for all your help!!!

"Jake Marx" <msnews@longhead.com> wrote in message
news:OayNUjHKEHA.2556@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi Frank,
>
> I think you could still use Bob's suggestion. When you create the[/color]
instance[color=blue]
> of Excel, just check the value of the application's Hwnd property. Then
> pass that value to the GetWindowThreadProcessId function to get the PID.
>
> In your case:
>
> Public Declare Function GetWindowThreadProcessId Lib "user32" _
> (ByVal hwnd As Long, lpdwProcessId As Long) As Long
>
> Sub Test()
> Dim objExcel As Excel.Application
> Dim lPID As Long
>
> Set objExcel = New Excel.Application
> GetWindowThreadProcessId objExcel.hwnd, lPID
> Debug.Print "PID: " & CStr(lPID)
> objExcel.Quit
> Set objExcel = Nothing
> End Sub
>
> --
> Regards,
>
> Jake Marx
> MS MVP - Excel
> www.longhead.com
>
> [please keep replies in the newsgroup - email address unmonitored]
>
>
> Frank DeLuccia wrote:[color=green]
> > Bob,
> >
> > Thanks for the hint but the Excel visible property is set to
> > false b/c this is an automated process without interaction, there
> > could be multiple instances of excel running, and I need the process
> > ID of the instance being created at runtime. The thought is if there
> > is an error in that instance running, I can kill that process using
> > the ID while leaving the other instances alone.
> >
> > Thanks for your time,
> > Frank
> >
> > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
> > news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=darkred]
> >> Hi Frank,
> >>
> >> Don't know about .NET, but this function gets a process id. Perhaps
> >> you can build into .NET
> >>
> >> Function ProcID() As Long
> >> Dim hwnd As Long
> >> Dim idProc As Long
> >> hwnd = FindWindow(vbNullString, "Microsoft Excel")
> >> Call GetWindowThreadProcessId(hwnd, idProc)
> >> ProcID = idProc
> >>
> >> End Function
> >>
> >>
> >> --
> >>
> >> HTH
> >>
> >> Bob Phillips
> >> ... looking out across Poole Harbour to the Purbecks
> >> (remove nothere from the email address if mailing direct)
> >>
> >> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote
> >> in message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...
> >>> Hello All,
> >>>
> >>> Hope eveyone is having a better morning than me today. Anyway,
> >>> I know the .NET framework has classes to obtain process ID's of
> >>> processes running in the task manager. My question is; Does .NET
> >>> have anything in it's bag of tricks to give me the process ID of an
> >>> instance I create through code?
> >>>
> >>> Example:
> >>>
> >>> Dim objExcel as Excel.Application
> >>>
> >>> objExcel = New Excel.Application <----- I want to know the
> >>> process ID right after I create this instance.
> >>>
> >>> Is there anyway I can get that info? Any guidance would be greatly
> >>> appreciated.
> >>>
> >>> -Thanks,
> >>> Frank[/color][/color]
>[/color]


Frank DeLuccia
Guest
 
Posts: n/a
#9: Nov 22 '05

re: Obtain a Process ID


Thanks, Guys, for all your help!!!

"Jake Marx" <msnews@longhead.com> wrote in message
news:OayNUjHKEHA.2556@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi Frank,
>
> I think you could still use Bob's suggestion. When you create the[/color]
instance[color=blue]
> of Excel, just check the value of the application's Hwnd property. Then
> pass that value to the GetWindowThreadProcessId function to get the PID.
>
> In your case:
>
> Public Declare Function GetWindowThreadProcessId Lib "user32" _
> (ByVal hwnd As Long, lpdwProcessId As Long) As Long
>
> Sub Test()
> Dim objExcel As Excel.Application
> Dim lPID As Long
>
> Set objExcel = New Excel.Application
> GetWindowThreadProcessId objExcel.hwnd, lPID
> Debug.Print "PID: " & CStr(lPID)
> objExcel.Quit
> Set objExcel = Nothing
> End Sub
>
> --
> Regards,
>
> Jake Marx
> MS MVP - Excel
> www.longhead.com
>
> [please keep replies in the newsgroup - email address unmonitored]
>
>
> Frank DeLuccia wrote:[color=green]
> > Bob,
> >
> > Thanks for the hint but the Excel visible property is set to
> > false b/c this is an automated process without interaction, there
> > could be multiple instances of excel running, and I need the process
> > ID of the instance being created at runtime. The thought is if there
> > is an error in that instance running, I can kill that process using
> > the ID while leaving the other instances alone.
> >
> > Thanks for your time,
> > Frank
> >
> > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
> > news:ekkj43GKEHA.3472@TK2MSFTNGP09.phx.gbl...[color=darkred]
> >> Hi Frank,
> >>
> >> Don't know about .NET, but this function gets a process id. Perhaps
> >> you can build into .NET
> >>
> >> Function ProcID() As Long
> >> Dim hwnd As Long
> >> Dim idProc As Long
> >> hwnd = FindWindow(vbNullString, "Microsoft Excel")
> >> Call GetWindowThreadProcessId(hwnd, idProc)
> >> ProcID = idProc
> >>
> >> End Function
> >>
> >>
> >> --
> >>
> >> HTH
> >>
> >> Bob Phillips
> >> ... looking out across Poole Harbour to the Purbecks
> >> (remove nothere from the email address if mailing direct)
> >>
> >> "Frank DeLuccia" <fdeluccia-RemoveThisInsert-@edifice-ims.com> wrote
> >> in message news:%23zHdrpGKEHA.2692@tk2msftngp13.phx.gbl...
> >>> Hello All,
> >>>
> >>> Hope eveyone is having a better morning than me today. Anyway,
> >>> I know the .NET framework has classes to obtain process ID's of
> >>> processes running in the task manager. My question is; Does .NET
> >>> have anything in it's bag of tricks to give me the process ID of an
> >>> instance I create through code?
> >>>
> >>> Example:
> >>>
> >>> Dim objExcel as Excel.Application
> >>>
> >>> objExcel = New Excel.Application <----- I want to know the
> >>> process ID right after I create this instance.
> >>>
> >>> Is there anyway I can get that info? Any guidance would be greatly
> >>> appreciated.
> >>>
> >>> -Thanks,
> >>> Frank[/color][/color]
>[/color]


Closed Thread