ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting excel process id (https://www.excelbanter.com/excel-programming/400380-getting-excel-process-id.html)

Asim

Getting excel process id
 
Hi,
I am working on excel automation. I want the get the handle and process
id for the excel process. Following is the way I am creating the excel
application.

Excel.Application xlApp = new Excel.Application();

There is one way of getting the handle (hwnd) to the excel process by making
the application visible, then setting a caption and getting the handle using
FindWindow method. But I don't want to make the application visible.
So is there any other way of doing it?
I am using Excel 2000, C# 2.0.

Regards,
Asim.


Chip Pearson

Getting excel process id
 
The Application object has an HWnd property, but I don't recall if it is
present in Excel 2000. You can use the FindWindow API call to find the HWnd.
In VB, this would be

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

Function GetXLHwnd() As Long
GetXLHwnd = FindWindow("XLMain", Application.Caption)
End Function

If you can be sure that you have only one instance of Excel running, you can
substitute vbNullString for Application.Caption. The Application need not be
visible for this to work.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Asim" wrote in message
...
Hi,
I am working on excel automation. I want the get the handle and process
id for the excel process. Following is the way I am creating the excel
application.

Excel.Application xlApp = new Excel.Application();

There is one way of getting the handle (hwnd) to the excel process by
making
the application visible, then setting a caption and getting the handle
using
FindWindow method. But I don't want to make the application visible.
So is there any other way of doing it?
I am using Excel 2000, C# 2.0.

Regards,
Asim.



Asim

Getting excel process id
 
Hi,
Thanks a lot. It works now.

Regards,
Asim.

"Chip Pearson" wrote:

The Application object has an HWnd property, but I don't recall if it is
present in Excel 2000. You can use the FindWindow API call to find the HWnd.
In VB, this would be

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

Function GetXLHwnd() As Long
GetXLHwnd = FindWindow("XLMain", Application.Caption)
End Function

If you can be sure that you have only one instance of Excel running, you can
substitute vbNullString for Application.Caption. The Application need not be
visible for this to work.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Asim" wrote in message
...
Hi,
I am working on excel automation. I want the get the handle and process
id for the excel process. Following is the way I am creating the excel
application.

Excel.Application xlApp = new Excel.Application();

There is one way of getting the handle (hwnd) to the excel process by
making
the application visible, then setting a caption and getting the handle
using
FindWindow method. But I don't want to make the application visible.
So is there any other way of doing it?
I am using Excel 2000, C# 2.0.

Regards,
Asim.




All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com