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

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

问题描述

我有一个程序(写在VB.NET)如下:

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

在我这运行几次,我得到了一堆EXCEL.EXE情况下,在我的任务管理器。我怎么可以杀死这些进程在code?所有的那些在code都试过了,没有工作。

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.

推荐答案

我不得不这样做了一段时间回来NET 1.1,所以请原谅生锈。

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

在EAPP,有一个Hwind(一个Win32窗口句柄 - HTTP: //msdn.microsoft.com/en-us/library/bb255823.aspx )或类似物体。我不得不使用和PInvoke的( http://www.pinvoke.net/default。 ASPX / user32.GetWindowThreadProcessId )来获取的进程ID。随着我能够做一个Process.Kill()上的exe文件。

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天全站免登陆