Strange issue with Process.GetProcessesByName count not working anymore.

Mortius Maximus 6 Reputation points
2022-08-11T19:37:19.657+00:00

I have..

Dim r As Integer = Process.GetProcessesByName("Server-Program").Count
Dim x As Integer = Process.GetProcessesByName("Game Example").Count

Then I check if the process is running by checking if r > 0 or if x > 0 ... simple, right?
It was all working just fine. Then it just stopped. With no code change.
Now r works just fine, but when I check for the other process, which is definitely running and the name hasn't changed and is for sure correct, it always returns 0. Literally nothing has changed with that program. I even made the program itself reveal it's process name into a textbox which I copied just in case.
It can no longer see the process. It shows up in Task Manager in the top section just like it always has. This all again was working just fine and for no reason that I can determine stopped working.
Why can I no longer see the process that is clearly there? Why does X always = 0 no matter how many copies of "Game Example" are running?
This has been giving me fits for hours now and I can't figure out what happened.
Thank you.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,608 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Dewayne Basnett 1,361 Reputation points
    2022-08-11T20:22:53.31+00:00

    You could add this to help with debugging,

            If r = 0 OrElse x = 0 Then  
                For Each pr As Process In Process.GetProcesses().OrderBy(Function(p) p.ProcessName)  
                    Debug.WriteLine(pr.ProcessName)  
                Next  
            End If