I need a little bit help with my program

paddygamer

New member
Joined
Oct 13, 2009
Messages
3
Programming Experience
Beginner
Okay i am trying to write a little program that checks for a process and kills is.

here is the code:
VB.NET:
Dim p As Process = Process.GetProcessesByName("Cheat Engine")(0)
        p.CloseMainWindow()
        Threading.Thread.Sleep(500)
        If Process.GetProcessesByName("Cheat Engine").Length > 0 Then
            p.Kill()
        End If
    End Sub

My problem is it´s woking ,yes if the programm ,,Cheat Engine" is running the process is getting killed.

But if the program is not running my program crashes. I do not have any Idea how to fix this. I hope you high-skillers can help me out.:D

(i am ussing VB 2008)
 
You can't get the first element in array (0) if there is no first element. You have to call GetProcessesByName and place result in variable, then check if this array contains any elements, if it does you can proceed.
 
VB.NET:
Dim ps() As Process = Process.GetProcessesByName("Cheat Engine")

For Each p As Process in ps
  'Do whatever
Next
 
Everything worked well. =) Thank you so much.

But i have another problem. I want to add an IF query to my program.
But i failed hard with that :mad: .

So i wanted to ask if you could help me out. The only thing i wanted to add to the code is :if the programm Cheat Enigne is found then Goto 1:


Thats all i want to add. I hope you can help me out a 2nd time.
Thanky in Advance

-Paddy
 
Everything worked well. =) Thank you so much.

But i have another problem. I want to add an IF query to my program.
But i failed hard with that :mad: .

So i wanted to ask if you could help me out. The only thing i wanted to add to the code is :if the programm Cheat Enigne is found then Goto 1:


Thats all i want to add. I hope you can help me out a 2nd time.
Thanky in Advance

-Paddy
I wont get into why you shouldn't use GoTo, other than say NEVER use GoTo

That being said, Your If statement would probably be something like:
VB.NET:
Dim ps() As Process = Process.GetProcessesByName("Cheat Engine")

If ps.length > 0I Then
  'It's running
Else
  'It's not running
End If
 
Back
Top