Last post Oct 22, 2019 09:17 AM by PatriceSc
Oct 17, 2019 11:26 AM|singhsalil2008|LINK
On windows server 2012R2, using GetWindowThreadProcessId, I am unable to get process id of object of an excel application(Excel.Application) though the Hwnd of this object is getting send correctly.
On Dev machine(windows 7), this process id is getting returned correctly, looks like some issue with the server.
I need to find above process id so that I could so that I could kill it(after finding all excel processes on the server).
Can you please help me resolve this.
Oct 17, 2019 11:49 AM|PatriceSc|LINK
You could likelly use https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.getprocesses?view=netframework-4.8 instead
to find "excel.exe". I suspect it is 0 because there is no active desktop session on which a window could be shown.
Make sure to do that only if you have a real problem (ie Excel doesn't close properly a common problem being blocked by a dialog with nobody to answer, you can disable them).
It is also strongly suggested to avoid using an end user interactive application as a programming library.
Oct 18, 2019 03:55 AM|singhsalil2008|LINK
Wanted to mention that I am using an ASP.net MVC application for this with c# as language. After a report generation my excel object is not getting closed and lies open on the server. Applied a no. of ways to close the excel objects but nothing is working
so thought of killing that particular process.
Using GetWindowThreadProcessId, on my dev machine(win 7), I am able to close the excel process but as mentioned above it does not closes on server(windows server 2012 R2).
I need not find all processes, need to find the excel one.
</div> </div> </div>
Oct 18, 2019 08:50 AM|Yang Shen|LINK
Usually, this Excel.Application library is not suggested to set in your server, sometimes it will throw error.
@PatriceSc's recommendation is helpful, or you can provide your related code to see if we can reproduce your problem and even solve it.
Again, it's not suggested in your server side.
Oct 18, 2019 09:31 AM|PatriceSc|LINK
Ok and so what if trying something such as
to find directly the Excel process rather than going through a UI related stuff on a server that doesn't show any UI ???
More likely you have the problem I alluded ealier when using an interactive application as if it is a programming library (ie Excel likely waits for some user input such as telling a file can't be written or if you want to quit Excel without saving etc...).
Edit: on your machine you do have a desktop session unlike the server (and you may have different settings or permission for Excel dialogs, it could even ask something on the frst launch etc...).
Oct 22, 2019 04:01 AM|singhsalil2008|LINK
I need to find that specific excel process which I am using to create report. Below code will find all excel process instances on server and kill them.
Please help me finding that specific excel process.
Oct 22, 2019 07:45 AM|PatriceSc|LINK
Ok but what about past suggestions? What if you try System.Diagnostics.Process.GetProcessesByName("Excel")?
Oct 22, 2019 08:45 AM|singhsalil2008|LINK
This will find all excel processes on server, I need to find the one I created.
Oct 22, 2019 09:17 AM|PatriceSc|LINK
How do you launch Excel ? The https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netframework-4.8 method returns
the process you created....
I Would try first to double check what happens but my guess is that you have a dialog that prevents Excel to go further...
Then at a later time I would reconsider using Excel as a programming library using the OpenXML SDK or whatever instead....