Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.dotnet.general,microsoft.public.dotnet.framework,microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Obtain a Process ID

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


  #2   Report Post  
Posted to microsoft.public.dotnet.general,microsoft.public.dotnet.framework,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in
message ...
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




  #3   Report Post  
Posted to microsoft.public.dotnet.general,microsoft.public.dotnet.framework,microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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" wrote in message
...
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" wrote in
message ...
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






  #4   Report Post  
Posted to microsoft.public.dotnet.general,microsoft.public.dotnet.framework,microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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:
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" wrote in message
...
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" wrote
in message ...
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Obtain a Process ID

Excel 2000 and below do not have the hwnd property so it is necessaryto find the Window handle by other means

You can't use "Microsoft Excel" with FindWindow (the caption is volatile). Instead use the Excel class, XLMAIN. This applies to ALL versions of Excel

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Lon

The class name is lpClassName, the caption is lpWindowName. Usually, just one or the other is specified.


  #6   Report Post  
Posted to microsoft.public.dotnet.general,microsoft.public.dotnet.framework,microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Obtain a Process ID

Thanks, Guys, for all your help!!!

"Jake Marx" wrote in message
...
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:
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" wrote in message
...
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" wrote
in message ...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to obtain my goal? Islic-ExcelChallenged Excel Discussion (Misc queries) 2 October 2nd 09 10:38 PM
Need to obtain Col Letter - VBA Emece Excel Discussion (Misc queries) 1 February 13th 09 03:47 PM
How To Obtain The Top 10% SMH Excel Discussion (Misc queries) 4 March 26th 08 01:09 PM
how to obtain sheet name? Khoshravan Excel Discussion (Misc queries) 7 May 22nd 06 01:32 AM
Need to know how to obtain this...please 0o0o0[_9_] Excel Programming 2 October 18th 03 04:28 PM


All times are GMT +1. The time now is 07:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"