473,382 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 10675
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: federico | last post by:
When I close an excel application opened from a python program with .Close() methood , in tasks manager is still present 'excel.exe' process and if I open manually an excel applicaion I have a...
5
by: KC | last post by:
Hi, I have code similar to this.. Dim xlApp As Object xlApp = CreateObject("Excel.Application", "\\MyServer") The call is from a asp.net (Intranet) application. \\Myserver is a network...
8
by: ChrisBowringGG | last post by:
When you use Application.Quit() on an Excel application, there can still be an instance of Excel running, as seen in Task Manager. You can try following the advice on MSDN: ...
1
by: Bernd Muent | last post by:
Hi together, I am using the following code in Visual Basic to open Word or Excel applications: Word: Dim w As Word.Application w = CType(CreateObject("Word.application"), Word.Application)...
2
by: Sri | last post by:
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 =...
1
by: myname | last post by:
Hello, in VB.Net, I use Excel to display results : dim xl as new Excel.Application // creates an Excel process // snip (putting values into cells) xl.Visible = true If the user closes the...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
2
by: =?Utf-8?B?TEJU?= | last post by:
Good Day, I have a web application created using ASP.NET (with VB.NET). The application allow user to browse Excel raw data file then the program will grab data from the file to perform further...
1
by: raul15791 | last post by:
Hi, I'm new to C#. I'm writing a program that open a new excel file, write into it and lastly close the file. But the program is that there will be a orphaned process named EXCEL.EXE left on the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.