杀死互操作应用程序 [英] Killing an interop Application process

查看:146
本文介绍了杀死互操作应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序中编写了以下内容(用VB.NET编写):

 导入Microsoft.Office.Interop.Excel 

公共类Form1
将eApp作为新的Excel.Application
Dim w As Excel.Workbook
w = eApp.Workbooks.Open(path.xls,ReadOnly := True)
..处理代码..
//尝试杀死excel应用程序
w.Close()
eApp.Workbooks.Close()
eApp.Quit()
结束类

当我运行这几次,我在我的任务管理器中获取一堆EXCEL.EXE实例。如何在代码中杀死这些进程?代码中的所有代码都已被尝试,并且没有起作用。

解决方案

我不得不在NET 1.1,所以请原谅生锈。在eApp上有一个Hwind(一个win32窗口句柄 - http://msdn.microsoft.com/en-us/library/bb255823.aspx )或类似的对象。我不得不使用和pInvoke( http://www.pinvoke.net/default .aspx / user32.GetWindowThreadProcessId )获取进程标识。因此,我能够在exe上执行一个Process.Kill()。



现在可能有更好的方法来实现,但这应该是有效的。


I have the following in a program (written in VB.NET):

Imports Microsoft.Office.Interop.Excel

Public Class Form1
    Dim eApp As New Excel.Application
    Dim w As Excel.Workbook
    w = eApp.Workbooks.Open( "path.xls", ReadOnly:=True)
    .. Processing Code ..
    //Attempts at killing the excel application
    w.Close()
    eApp.Workbooks.Close()
    eApp.Quit()
End Class

When I run this a couple of times, I get a bunch of EXCEL.EXE instances in my task manager. How can I kill these processes in code? All of the ones in the code have been tried and did not work.

解决方案

I had to do this a while back in NET 1.1, so please forgive the rust.

On the eApp, there was a Hwind (a win32 window handle - http://msdn.microsoft.com/en-us/library/bb255823.aspx ) or similar object. I had to use that and a pInvoke (http://www.pinvoke.net/default.aspx/user32.GetWindowThreadProcessId ) to get the process id. With that I was able to do a Process.Kill() on the exe.

There maybe a better way to do it now, but this should work.

这篇关于杀死互操作应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆