如何杀死所有开放的powerpoint进程?

时间:2013-08-19 17:58:36

标签: vb.net

我试图杀死所有开放的powerpoint进程,但我编写的代码只会杀死一个开放进程。

    '-- get a collection of processes running
    Dim foo() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
    '-- go through each one looking for the internet explorer name
    For Each temp As Diagnostics.Process In foo

        'For Word Files opened in Office
        If temp.ProcessName = "POWERPNT" Then
            temp.Kill() '-- if I find it, kill it.
            '                Exit For '-- exit the for loop
        End If

2 个答案:

答案 0 :(得分:1)

尝试

Dim foo() as process = Process.GetProcessByName("POWERPNT")

For Each temp As Process In foo

    temp.Kill()

Next

答案 1 :(得分:0)

您只会找到POWERPNT.exe的单个实例,因为

  

Word(Winword.exe),Excel(Excel.exe)和Microsoft Access(MSAccess.exe)的多个实例可以同时运行。因此,这些服务器被定义为单用户(多实例)服务器。在任何给定时间只能运行一个PowerPoint(Powerpnt.exe)实例。因此,PowerPoint是一个多用途(单实例)服务器。

阅读How to use Visual C# to automate a running instance of an Office program以获取完整的文档。