无法破坏Excel进程;试过几乎所有事情! [英] Can't destroy Excel Process; tried Just about everything!

查看:63
本文介绍了无法破坏Excel进程;试过几乎所有事情!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试使用.NET和Excel。我安装了Office 2003并选择了

..NET编程支持选项,因此它安装了所有那些PIA,因为MS

sugests。但是我找不到破坏Excel进程的方法,它仍然在taks manager''Processes as running中挂起

。我正在尝试非常简单的代码

(见下文),但Excel不会消失,我尝试了任何我可以在MSDN或Google上找到的
。甚至调用WIN32 API来销毁Excel。但

NOTHING有效,任何帮助都将受到赞赏。

''API声明:

公共声明函数FindWindow Lib" user32"别名FindWindowA (ByVal

lpClassName As String,ByVal lpWindowName As String)As long


Public Declare Function SendMessage Lib" user32"别名SendMessageA (ByVal

hwnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As

Long)As Long


''实际的VB.NET代码:


Public Const WM_DESTROY =& H2


Public Const WM_USER =& H400


Dim exApplication As New Excel.Application


exApplication.DisplayAlerts = False


exApplication.Caption =" ; Microsoft Excel(关闭)"


Dim wrk As Excel.Workbook


wrk = exApplication.Workbooks.Add()


Dim settings As New SiteSettings


Dim dir As String = settings.getAppSettingValue(" TempDirectory")


Dim fileName As String = dir& Session.SessionID& " .xls"


wrk.SaveAs(fileName)


wrk.Close()


NAR(方舟)


wrk =没什么


exApplication.Quit()


NAR(exApplication)


exApplication = Nothing


''杀戮过程


Dim hwnd As很长


Dim lngResult As Long


hwnd = FindWindow(" XLMAIN"," Microsoft Excel(关闭)")


如果hwnd<> 0然后


lngResult = SendMessage(hwnd,WM_USER + 18,0,0)

lngResult = SendMessage(hwnd,WM_DESTROY,0, 0)


结束如果


私人子NAR(ByRef o As Object)


昏暗我作为整数= -2


尝试


而(i<> 0&i<> -1)


i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)


结束时


抓住


最后


o =没什么


结束尝试


End Sub

Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
..NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs
in the taks manager'' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
''API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

'' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

'' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub

推荐答案

.. NET语言不像VBA那样进行清理。


除了将变量设置为Nothing之外,在

末尾添加以下代码以加快垃圾收集。

GC.Collect()

GC.WaitForPendingFinalizers()

GC.Collect()

GC.WaitForPendingFinalizers()


和做不要忘记退出Excel。


-
http://www.standards.com/; 请参阅Howard Kaikow的网站。

" LP" < lp@a.com>写在消息

新闻:uO ************** @ TK2MSFTNGP12.phx.gbl ...
..NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow''s web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
你好,

我正在尝试使用.NET和Excel。我安装了Office 2003并选择了.NET编程支持选项,因此它安装了所有那些PIA,因为MS
sugest。但是我找不到破坏Excel进程的方法,它仍然在taks manager''Processes as running中挂起。我正在尝试非常简单的代码
(见下文),但Excel不会消失,我尝试了任何我可以在MSDN或谷歌上找到的东西。甚至调用WIN32 API来销毁Excel。但是
NOTHING有效,任何帮助都将受到赞赏。
''API声明:
公共声明功能FindWindow Lib" user32"别名FindWindowA (ByVal
lpClassName As String,ByVal lpWindowName As String)As Long

Public Declare Function SendMessage Lib" user32"别名SendMessageA
(ByVal hwnd As Long,ByVal wMsg as Long,ByVal wParam as Long,ByVal lParam As
Long)As long

''实际VB.NET代码:

Public Const WM_DESTROY =& H2

公共Const WM_USER =& H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption =" Microsoft Excel(关闭)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue(" TempDirectory")

> Dim fileName As String = dir& Session.SessionID& < .xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk =没什么

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' '杀戮过程

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow(" XLMAIN"," Microsoft Excel(to关闭)")

如果hwnd<> 0然后

lngResult = SendMessage(hwnd,WM_USER + 18,0,0)

lngResult = SendMessage(hwnd,WM_DESTROY,0,0)

私人子NAR(ByRef o As Object)

Dim i As Integer = -2

尝试
< while(i<> 0&i<> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
结束时

抓住

最后

o =什么都没有

结束尝试

End Sub
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
.NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs
in the taks manager'' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
''API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

'' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

'' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub



感谢您的回复。我实际上已经有了.Collect()。我补充说:

GC.Collect()GC.WaitForPendingFinalizers()两次,但仍然是Excel Process

运行。还有其他想法吗?



Howard Kaikow < KA **** @ standards.com>在消息中写道

新闻:Oo ************** @ TK2MSFTNGP10.phx.gbl ...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET语言做nopt以与VBA相同的方式进行清理。

除了将变量设置为Nothing之外,在代码的末尾
添加以下内容以加快垃圾收集。
GC.Collect ()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

并且不要忘记退出Excel。

-
http://www.standards.com/; 请参阅Howard Kaikow的网站。
LP < lp@a.com>在消息中写道
新闻:uO ************** @ TK2MSFTNGP12.phx.gbl ...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end of your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow''s web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
你好,
我正在尝试使用.NET与Excel。我安装了Office 2003并选择了.NET编程支持选项,因此它安装了所有那些PIA,因为MS
sugest。但是我找不到破坏Excel进程的方法,它仍然是
挂在taks manager''Processes as running中。我正在尝试非常简单的代码
(见下文),但Excel不会消失,我尝试了任何我可以在MSDN或谷歌上找到的东西。甚至调用WIN32 API来销毁Excel。但是
NOTHING有效,任何帮助都将受到赞赏。
''API声明:
公共声明功能FindWindow Lib" user32"别名FindWindowA
(ByVal lpClassName As String,ByVal lpWindowName As String)As Long

Public Declare Function SendMessage Lib" user32"别名SendMessageA
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
.NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs in the taks manager'' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
''API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"


(ByVal


(ByVal

hwnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As
Long)As long实际的VB.NET代码:

Public Const WM_DESTROY =& H2

公共Const WM_USER =& H400


exApplication.DisplayAlerts = False

exApplication.Caption =" Microsoft Excel(关闭)"


wrk = exApplication.Workbooks.Add()

昏暗的设置作为新的SiteSettings

Dim dir As String = settings.getAppSettingValue(" TempDirectory")
Dim fileName As String = dir& Session.SessionID& < .xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk =没什么

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' '杀戮过程

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow(" XLMAIN"," Microsoft Excel(to关闭)")

如果hwnd<> 0然后

lngResult = SendMessage(hwnd,WM_USER + 18,0,0)

lngResult = SendMessage(hwnd,WM_DESTROY,0,0)

私人子NAR(ByRef o As Object)

Dim i As Integer = -2

尝试
< while(i<> 0&i<> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
结束时

抓住

最后

o =什么都没有

结束尝试

End Sub
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

'' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

'' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub




别忘了调用Marshall.ReleaseComObject(yourXLinstanceObjectVari able)
退出Excel后,您已实例化的每个COM对象的



" LP" < lp@a.com>在消息中写道

新闻:uy ************** @ TK2MSFTNGP14.phx.gbl ...
Don''t forget to call Marshall.ReleaseComObject(yourXLinstanceObjectVari able)
for EACH COM object you''ve instanced after you quit Excel.

"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
感谢您的回复。我实际上已经有了.Collect()。我补充说:
GC.Collect()GC.WaitForPendingFinalizers()两次,但仍然是Excel Process
正在运行。还有其他想法吗?



Howard Kaikow < KA **** @ standards.com>在消息中写道
新闻:Oo ************** @ TK2MSFTNGP10.phx.gbl ...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process
is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET语言不会清理它VBA的方式。

除了将变量设置为Nothing之外,在
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end
的末尾添加以下


以加快垃圾收集的速度。
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

并且不要忘记退出Excel。

http://www.standards.com/; 请参阅Howard Kaikow的网站。
LP < lp@a.com>在消息中写道
新闻:uO ************** @ TK2MSFTNGP12.phx.gbl ...

your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow''s web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
>你好,
>
>我正在尝试使用.NET与Excel。我安装了Office 2003和
>选择
> .NET编程支持选项,因此它安装了所有那些PIA,如MS
> sugests。但我找不到破坏Excel进程的方法,它仍然挂起>在taks经理''流程中运行。我正在尝试非常简单的代码
> (见下文),但Excel不会消失,我尝试了任何我
>可以
>在MSDN或Google上找到。甚至调用WIN32 API来销毁Excel。但是
>没有工作,任何帮助将不胜感激。
> ''API声明:
>公共声明函数FindWindow Lib" user32"别名FindWindowA (ByVal> lpClassName As String,ByVal lpWindowName As String)As Long
>
>公共声明函数SendMessage Lib" user32"别名SendMessageA
> Hello,
>
> I am trying to use .NET with Excel. I installed Office 2003 and
> selected
> .NET programming suport option, so it installed all those PIA, as MS
> sugests. But I can not find a way to destroy Excel process, it still hangs > in the taks manager'' Processes as running. I am trying very simple code
> (see below), but Excel wont go away, I tried just about anything I
> could
> find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
> NOTHING works, Any help will be appreciated.
> ''API declaration:
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal > lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"


(ByVal


(ByVal

> hwnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As
> Long)长得好
>
> ''实际的VB.NET代码:
>
> Public Const WM_DESTROY =& H2
>
> Public Const WM_USER =& H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption =" Microsoft Excel(关闭)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
>昏暗设置为新网站设置
>
> Dim dir As String = settings.getAppSettingValue(" TempDirectory")
>
> Dim fileName As String = dir& Session.SessionID& " .xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk =没什么
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> ''杀戮过程
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow(XLMAIN,Microsoft Excel(关闭))
>
>如果hwnd<> 0然后
>
> lngResult = SendMessage(hwnd,WM_USER + 18,0,0)
>
> lngResult = SendMessage(hwnd,WM_DESTROY,0,0)
>
>结束如果
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
>试试
>
>而(i<> 0&i<> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
>结束时
>
>抓住
>
>最后
>
> o =没什么
>
>结束尝试
>
>结束子
>
>
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
> Long) As Long
>
> '' actual VB.NET Code:
>
> Public Const WM_DESTROY = &H2
>
> Public Const WM_USER = &H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption = "Microsoft Excel (to close)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
> Dim settings As New SiteSettings
>
> Dim dir As String = settings.getAppSettingValue("TempDirectory")
>
> Dim fileName As String = dir & Session.SessionID & ".xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk = Nothing
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> '' Kill process
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>
> If hwnd <> 0 Then
>
> lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>
> lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>
> End If
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
> Try
>
> While (i <> 0 And i <> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
> End While
>
> Catch
>
> Finally
>
> o = Nothing
>
> End Try
>
> End Sub
>
>





这篇关于无法破坏Excel进程;试过几乎所有事情!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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