Strange issue with Process.GetProcessesByName count not working anymore.
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.
Did you check if
For Each p In Process.GetProcesses.OrderBy(Function(x) x.ProcessName) Console.WriteLine("'" & p.ProcessName & "'") Next
displays the expected name?
I get errors with that code. I'm not sure how to change it to work. What is X in your example? In mine it's an integer. I'm sorry, I just don't know how to make that work.
It works (in Visual Studio 2022, Console application). What error did you get? X is a local variable, which does not have to be defined. Since you already have an x variable, then use any different unused name in the above test.
What I did was make the program spit out it's process name using a different code. It put it into a textbox. I copied and pasted it into the other program to make sure nothing was wrong. It still won't see it anymore. I've made a whole new program named "MCG" now and it won't see it. I can see my other program with the same exact code just fine. It makes 0 sense.
Did you check if Process.GetProcesses sees and lists that names?
Yes. It def does.
EDIT: No I was using something similar but not process.getprocesses ... I was using where it just returned the name of the current process, not all of them. Now I see that I made that mistake here, sorry about that. Thanks again for the help.
Here is the exact current code in the one program. This is the System_Checker program beginning:
Dim r As Integer = Process.GetProcessesByName("Raft").Count
Dim x As Integer = Process.GetProcessesByName("The Forest").Count
If x Or r > 0 Then
Dim q As Integer = Process.GetProcessesByName("MCG").Count
If q = 0 Then
now, there is a lot more code below, but I'm just trying to not get the q=0 message to trigger because the only way that this program is even running is when MCG runs it. So MCG HAS to be running before this code gets called. This code is on a timer tick every 10 seconds. I will keep getting the q=0 message every 10 seconds even though MCG is running. Nothing will happen though if the games arn't running.
Now MCG is checking to make sure system_checker is running and if not it will run it again. That program is hidden from the screen and alt+tab, taskbar, etc... the two programs make sure the other one can't be ended. System_checker just makes sure the anti-cheat "MCG" is running and if not should run it as well but no longer works. MCG then looks for WeMod and other cheats and closes them. All of that works great.
So basically I'm trying to make an anti-cheat for games we play to prevent our players from cheating, because they keep cheating... this was working just fine on my computer while I was testing it but then for some unknown reason it can no longer detect the "MCG" process. The process name is "MCG". It is MCG in task manager. But q ALWAYS equals 0.
MCG checks using similar code to see if "system checker" is running and it works just fine. Here is one of the spots that works just fine...
Dim x As Integer = Process.GetProcessesByName("System Checker").Count
If x = 0 Then
Dim proc3 As New System.Diagnostics.Process()
proc3 = Process.Start("c:\program files (x86)\steam\config\system checker.exe", "")
More code below but that is pretty much the same code detecting a program I made the exact same way as the other one and this one works great.
Any ideas what I'm doing wrong or can try differently?
okay, I figured out what you meant for me to do. I made a new console app and used your code and I looked through everything and there was no MSG... I'm trying to figure out if it is one of these other processes... long list...
thanks... why is it not showing up?? so confused.
Okay, thanks a lot Viorel-1... I think I got it figured out. I don't understand why getcurrentprocess returned MCG like it shows in task manager.. but it is clearly going by the executable name, which is raft because I replaced the real raft executable with the anti-cheat and renamed the real raft executable to uninstall to be tricky. So it was seeing "raft", which was the anti-cheat, then going to the next step checking for "MSG" which of course didn't exist. Uninstall is also running so I can check for that name instead of "raft". I hope I'm right but I think this is the case here. I appreciate your help. All of this just to keep people from cheating in the games we play... I swear.
Sign in to comment
Sort by: Most helpful
You could add this to help with debugging,
I tried that but got nothing.
I have two programs running. They both look for each other and a game. They only start working when the game is running and they detect that just fine. One of the programs detects the other one just fine with the exact same code.
I made a whole new project and wrote it again, twice now. One line works just fine, the next doesn't. It can detect the game but then it can't detect that the anti-cheat is running. Now I have it named MCG just to have an easier name. My other project can detect the other one with the name "System Checker" just fine. It's count with be > 0. But when using the same code to check for "MCG" or any of the other names I've given it, it returns 0. Exact same code.
It was working fine. As far as I know nothing had changed. Even with a brand new program with a different process name... it is just undetectable for no reason. I've rebooted twice and reinstalled Visual Studio (it also stopped letting me publish one of the programs for no reason and even a reinstall did not fix that, had to make a new program and copy the code over for it to publish it, no clue why).
I don't know why your code doesn't do anything. I get nothing in my debug window at all.
What? 'I tried that but got nothing.' You should've got a list of all of the processes running.
Sign in to comment