[Tutorial][Function] Doing something if a process is closed or open.

Posts 1–5 of 5 · Page 1 of 1
[Tutorial][Function] Doing something if a process is closed or open.
ProcessIsOpen(String) Function

Function

Code:
Function ProcessIsOpen(ByVal ProcessName As String)
        Dim Process As New Process()
        Dim CacheHolder = ""
        For Each Process In Process.GetProcesses(My.Computer.Name)
            On Error Resume Next
            CacheHolder = CacheHolder + " " + Process.ProcessName + ".exe"
        Next
        If CacheHolder.ToString.Contains(ProcessName) Then
            Return 1
        Else
            Return 0
        End If
    End Function

Example Of Usage


Code:
if ProcessIsOpen("notepad") Then
Msgbox("Notepad is Running")
Else
Msgbox("Notepad is Closed")
End if
^* The Above code will display a message box saying
"Notepad Is Running" if notepad is open, and if its closed it will say Notepad is Closed*^



Why can this be useful?


If you don't want a user using your program with another one then you can use this function to set your program to close; For example per say your program holds values you can have it close if it sees cheat engine open.



Closing your program, when another one opens.

Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If ProcessIsOpen("notepad.exe") Then
Me.Close()
End If
End Sub


I think that pretty much covers it. if you have any questions feel free to ask, but if you want to flame I would prefer you wouldn't, and I am sure I could of done it a better way, but should I spend time editing to make it look professional, when it works as it is.


Credits


Lolland - For Having a account on MPGH
PixieCorp - For Having a MSN
NextGen1 - Just because if he wasn't hear it would be wierd.
BombsAway### - I liked all his tuts when he used to post them
Coder Never - Coding it HIMSELF with Help of Visual Basic 2008 and Microsoft and Bill Gates
Nice tutorial, thanks + rep.

Will definitely come in useful.

KEEP UP THE GOOD WORK.
i learned this in another way...
hmmm good tut.
Not bad, Decent
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us