471,596 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

How to find the process id of excel application in ASP.Net

Sri
I am writing an asp.net applicaition using VB coding.

In a function, I am opening an excel file with the following code,
Dim objExcel As Object
Dim objWorkBook As Object
objExcel = CreateObject("Excel.Application")
objWorkBook = objExcel.Workbooks.Open(targetfilename)
* targetfilename is a variable that stores the excel file name and path.

In the error handler,

I want to kill only the excel application created using previous line of
code. There can be any other excel application running in the server that
were not created by this application. How will I identify the process ID of
this excel application through code and kill the process.

Jul 22 '05 #1
2 10555
On Thu, 30 Jun 2005 03:56:01 -0700, Sri <Sr*@discussions.microsoft.com> wrote:

¤ I am writing an asp.net applicaition using VB coding.
¤
¤ In a function, I am opening an excel file with the following code,
¤ Dim objExcel As Object
¤ Dim objWorkBook As Object
¤ objExcel = CreateObject("Excel.Application")
¤ objWorkBook = objExcel.Workbooks.Open(targetfilename)
¤ * targetfilename is a variable that stores the excel file name and path.
¤
¤ In the error handler,
¤
¤ I want to kill only the excel application created using previous line of
¤ code. There can be any other excel application running in the server that
¤ were not created by this application. How will I identify the process ID of
¤ this excel application through code and kill the process.

You could use the FindWindow API function call
(http://msdn.microsoft.com/library/de...findwindow.asp)

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Int32
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg
As Int32, _
ByVal wParam As Int32, ByVal
lParam As Int32) As Int32

Public Function TerminateExcel()

Dim ClassName As String
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12

Do

ClassName = "XLMain"
WindowHandle = FindWindow(ClassName, Nothing)

If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0)
End If

Loop Until WindowHandle = 0

End Function
Paul
~~~~
Microsoft MVP (Visual Basic)
Jul 22 '05 #2
Sri
Thank you. I have one more issue in context to this same kill process
I have a excel report generated in asp.net.
I create a temporary excel file in the server and the report is generated in
the temproray file. The file is created only through asp.net code and can
never be opened manually in the microsoft excel application since security
rights doesn't allow the user to view the path.

The code,
If File.Exists(targetfilename) Then File.Delete(targetfilename)

throws exception some times, if the file is used by some other process.
The reason could be due to some error created when the report was prevuiosly
executed.

The I open the taskmanager, goto process, select Image name excel.exe ,
Image name as asp.net and click end process. Thus the line of code executes
after this.

Please let me know how I can do this in asp.net

Your advice will greatly help me to program better.
------

"Sri" wrote:
I am writing an asp.net applicaition using VB coding.

In a function, I am opening an excel file with the following code,
Dim objExcel As Object
Dim objWorkBook As Object
objExcel = CreateObject("Excel.Application")
objWorkBook = objExcel.Workbooks.Open(targetfilename)
* targetfilename is a variable that stores the excel file name and path.

In the error handler,

I want to kill only the excel application created using previous line of
code. There can be any other excel application running in the server that
were not created by this application. How will I identify the process ID of
this excel application through code and kill the process.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by federico | last post: by
1 post views Thread by Bernd Muent | last post: by
1 post views Thread by myname | last post: by
9 posts views Thread by Doug Glancy | last post: by
2 posts views Thread by =?Utf-8?B?TEJU?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.