Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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.


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
Using excel to process QIF file John Keith Excel Discussion (Misc queries) 0 November 14th 09 07:15 AM
Excel Process Doesn't End :-( Viperpurple Excel Programming 0 June 17th 05 09:41 AM
Kill Excel Process Mike Moore[_2_] Excel Programming 5 March 17th 05 08:55 AM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
How to count process running time ( process not finished) miao jie Excel Programming 2 January 12th 05 06:01 AM


All times are GMT +1. The time now is 05:16 PM.

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

About Us

"It's about Microsoft Excel"