LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

EXCEL.EXE process is keep running even after closing all the handles

Solved!
Go to solution

I am using Excel Report Instrument functions  for creating excel application and sheet,workbook after reading/writing in to excel file am closing all the handles using CA_DiscardObjHandle (handle);     even after file is getting closed m checking it in TaskManager then one EXCEl.EXE process is keep running there,pls let me know how to deal with this....

0 Kudos
Message 1 of 14
(41,641 Views)

Hi Ajoy,

 

       I dont know the CVI funtion. But you can do this using TaskKill function in command prompt

 

open the command prompt and try the following command

 

c:\>taskkill /f /im excel.exe

 

Thanks and Regards

NB

0 Kudos
Message 2 of 14
(41,611 Views)

A Kumar:

 

Have you tried running the example program excelreportdemo.prj that ships with CVI?  It ends the excel process by discarding multiple handles, and it works even if you're editing a cell or have an Excel dialog open, etc.  Try running this without modification and verify that the excel process is closed when you quit the CVI app.

 

Here's the Quit function from excelreportdemo.  It checks for and closes handles for the worksheet, chart, workbook, and excel application.

 

int CVICALLBACK Quit (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
        {
        case EVENT_COMMIT:
            if (worksheetHandle)
                CA_DiscardObjHandle(worksheetHandle);
            if (chartHandle)
                CA_DiscardObjHandle(chartHandle);
            if (workbookHandle)
            {
                ExcelRpt_WorkbookClose(workbookHandle, 0);
                CA_DiscardObjHandle(workbookHandle);
            }
            if (applicationHandle)
            {
                ExcelRpt_ApplicationQuit(applicationHandle);
                CA_DiscardObjHandle(applicationHandle);
            }
            QuitUserInterface (0);
            break;
        }
    return 0;
}

0 Kudos
Message 3 of 14
(41,605 Views)

Hi Nagraj,

      Thanks for ur reply. No I wanted to kill it from my CVI application, pls let me know if u have any idea

0 Kudos
Message 4 of 14
(41,591 Views)

Hi AI S,

 

I have tried with this , but it works for one case i.e. if I am opening and simply closing the excel without doing any operation on the file its killing the excel.exe process fine. But If I am doing any operation on excel after opening it, like read/write etc then am closing the file & clearing handles using same CA_DiscardObjHandle() its not killing the excel.exe process. I am not getting why its not able to kill the process after doing some manipulation on it?

0 Kudos
Message 5 of 14
(41,589 Views)

excelreportdemo manipulates the file: after opening Excel, it writes data, formats cells, adds calculations, adds a graph, and lets you manipulate that graph.  After doing all those actions, I also manually my some edits to the spreadsheet.  After all that, I still have no problem quitting Excel.

 

Using the unmodified excelreportdemo, were you able to do anything in excel to force excel stay open?

 

Are you calling ExcelRpt_WorkbookClose() and ExcelRpt_ApplicationQuit() in addition to discarding the handles?  You need to do both, not just discard the handles.  See the code I posted from the excelreportdemo example.

Have you checked to see if you get any errors discarding the handles?

Are you sure that you are passing the correct handle to CA_DiscardObjHandle()?

0 Kudos
Message 6 of 14
(41,569 Views)

Hi! Kumar,

 

You probably add new objects and object handles when modifying the example codes.

I had similar issue before, and the reason is the added objects are not discarded (cleaned up) properly when terminating the program.  Once you clean them up, the EXCEL.EXE will disapear.

0 Kudos
Message 7 of 14
(41,552 Views)

Hey Kumar -

 

I've helped a number of people debug this exact issue, and it has almost always turned out to be exactly what dcl9000 has said.  If you are using LabWindows/CVI 9.0 or later, the fastest way to find this out is to enable resource tracking (Options>Build Options>Debugging Level>Extended), and then run your program start to finish.  The resource tracking window will display after your program completes normally if you have resources you have not disposed of, such as Excel automation handles.  Take a look at this documentation for more information.

 

NickB

National Instruments

Message 8 of 14
(41,531 Views)

Yes AI,

 

M closing the workbook & quiting the application using same functions as you mentioned.....one reason might be as DCl has posted...I will try to track all the handles and will see wat is happening.................meanwhile if you have any suggestions pls keep posting..

 

Thanks

0 Kudos
Message 9 of 14
(41,507 Views)

Not sure what version of Excel you are using, but I have an application using Excel that works fine with Excel 2003 but leaves the Excel process running when using Excel 2007.

--
Martin
Certified CVI Developer
0 Kudos
Message 10 of 14
(41,489 Views)