none
GetProcessByName. Not in x86? RRS feed

  • Question

  • Hey, apprentice level coder, here. Started messing with vb late last year. Also don't know if this is the proper spot to post this, so I apologize.

    Like the title says, I have the Sub fetching all instances of a specific process (in this case, Microsoft Excel) and killing them. The code works, but only on my desktop (Win10 Home x64). It will not, however, work on my notebook (Win10 Home x86), nor on my work pc (Win7 Enterprise x86). It fetches nothing, zero instances.

    So I started having second thoughts... IS this sub limited for 32bit systems? Does it only work on 64bit OS? And I found nothing. The application is made in x86, not x64. I actually thought it might've been that, an x64 app not working in x86 OS, but it works as is, it's an x86 app which this sub works in an x64 OS...

    So now I'm confused as to why it works on only half the tested PCs.

    Code for reference:

    Private Sub close()
            workbook.Close()
            APP.Quit()
            Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("Microsoft Excel")
            For Each proc As System.Diagnostics.Process In pList
                proc.Kill()
            Next
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Sub
    Any help from the veterans is appreciated.

    Tuesday, February 20, 2018 11:48 AM

Answers

  • Yes, it works fine provided you use the process name of "Excel" rather than "Microsoft Excel"

            Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("Excel")
    


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Oryngton Thursday, February 22, 2018 1:13 PM
    Wednesday, February 21, 2018 3:44 PM

All replies

  • Have you checked the names of processes that are returned by System.Diagnostics.Process.GetProcesses()? Maybe Excel has a different process name.

    Tuesday, February 20, 2018 6:38 PM
  • Yes, it works fine provided you use the process name of "Excel" rather than "Microsoft Excel"

            Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("Excel")
    


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Oryngton Thursday, February 22, 2018 1:13 PM
    Wednesday, February 21, 2018 3:44 PM
  • That does work; I had not considered that. Which is weird, the process name is still "Microsoft Excel" on the 32bit systems.
    Thursday, February 22, 2018 1:13 PM