?
Solved

Killing the Excel Process with out shutting down the server

Posted on 2003-03-18
8
Medium Priority
?
292 Views
Last Modified: 2008-03-06
Hello
I am trying to create the Excel files via VB DLL which is being called by ASP file on the server. But some times if there is some problem it does not create the excel file and does not stop the Excel process on NT Preoceses Tesk manager. the only solution i have is to reboot the serever . can any one help me how can i kill the Excel process with out rebooting the server/system.

Many Thanks
0
Comment
Question by:tygt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
farzinm earned 300 total points
ID: 8159591
you can use error handling in your DLL code

on error resume next
'your entire code here
if err then
   Set m_oExcelWS = Nothing 'excel worksheet object
   m_oExcelWBk.Close 'close excel workbook object
   Set m_oExcelWBk = Nothing 'excel worksheet object
   m_oExcel.Quit  'excel application object
   Set m_oExcel = Nothing 'excel application object    
   function name = "Error occured " & err.decription
  'This will return the error back to your ASP code so that you would know what error occured
end if
0
 
LVL 4

Expert Comment

by:iozturk
ID: 8159653
Tre is a tool in  www.sysinternals.com, that is called Process explorer. You can kill any thing you want by using it. You can also search for which process is using a specific dll.
0
 

Author Comment

by:tygt
ID: 8160037
hello farzinm
uer error hendling has helped me but i cant find what is the error on browser it just says "exception occured <mathod name>". it does not tell me the specific error.
Many Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:farzinm
ID: 8160159
I wrongly spelled it
it should be err.description
This will tell you what error occurred.
Also by
functionname =err.description
I mean that if you have your entire code inside a function named "functionname" only then can you use

functionname = "Error occured " & err.description


 
0
 
LVL 4

Expert Comment

by:farzinm
ID: 8160226
Public Function displayExcel(parameters) As String

on error resume next
'your entire code here
if err then
  Set m_oExcelWS = Nothing 'excel worksheet object
  m_oExcelWBk.Close 'close excel workbook object
  Set m_oExcelWBk = Nothing 'excel worksheet object
  m_oExcel.Quit  'excel application object
  Set m_oExcel = Nothing 'excel application object    
  displayExcel = "Error occured " & err.description
 'This will return the error back to your ASP code so that you would know what error occured
end if
End Function

Hope this makes it more clear
Good Luck!
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8160750
Option Explicit
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1
Private Const PROCESS_QUERY_INFORMATION = 1024
Private Const PROCESS_VM_READ = 16
Private Const MAX_PATH = 260

Function KillProcess(strApp As String)
  Dim hProcess, cb, cbNeeded, NumElements, cbNeeded2, NumElements2, lRet, nSize, ExCode, i As Long
  Dim ProcessIDs() As Long
  Dim Modules(1 To 200) As Long
  Dim ModuleName As String
  cb = 8
  cbNeeded = 96
  Do While cb <= cbNeeded
     cb = cb * 2
     ReDim ProcessIDs(cb / 4) As Long
     lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
  Loop
  NumElements = cbNeeded / 4
  For i = 1 To NumElements
     hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ Or PROCESS_TERMINATE, 0, ProcessIDs(i))
     If hProcess <> 0 Then
         lRet = EnumProcessModules(hProcess, Modules(1), 200, cbNeeded2)
         If lRet <> 0 Then
            ModuleName = Space(MAX_PATH)
            nSize = 500
            lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
            If InStr(1, UCase(Trim(ModuleName)), UCase(Trim(strApp))) <> 0 Then
               lRet = GetExitCodeProcess(hProcess, ExCode)
               lRet = TerminateProcess(hProcess, ExCode)
            End If
         End If
     End If
  lRet = CloseHandle(hProcess)
  Next
  Exit Function
End Function

'Kill it with
Private Sub Command1_Click()
KillProcess ("excel.exe")
End Sub

0
 
LVL 58

Expert Comment

by:Gary
ID: 9315973
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by farzinm

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question