Resolved Need Urgent Help - Process Name Check needs to be case-insensitive

Untamed

Well-known member
Joined
Jul 25, 2009
Messages
53
Programming Experience
5-10
Hello, I put this at the top of my project:
VB.NET:
Option Compare Text

Here is the sub that contains the process name check:
VB.NET:
    Sub AC3()
        Dim ProcessList As System.Diagnostics.Process()
        ProcessList = System.Diagnostics.Process.GetProcesses()
        Dim Proc As System.Diagnostics.Process
        For Each Proc In ProcessList
            Dim procname As String = Proc.ProcessName
            Dim string1 As String = "hack"
            Dim string2 As String = "cheat"
            Dim string3 As String = "inject"
            If procname.Contains(string1) Or procname.Contains(string2) Or procname.Contains(string3) Then
                killProcess("M2F")
                killProcess("ac2.exe")
                System.Diagnostics.Process.GetCurrentProcess.Kill()
            End If
        Next
    End Sub

No errors, but it only checks the lowercase hack/cheat/inject. I need it to be case insensitive when checking it. Any help, please? It is very urgent :| Thanks.

UPDATE: Figured it out and tested and it works. I put, right after dim procname...
VB.NET:
procname = procname.ToLower()
^^ works great, thanks anyway all :) I hope this helps someone.
 
Last edited:
Setting Option Compare to Text in your code file isn't going to have any affect on the way the String.Contains method behaves because it's implementation isn't in your code file, or even in your project for that matter. Setting Option Compare to Text only affects comparisons made where it's set.

Unfortunately String.Contains doesn't have a case-insensitive overload but IndexOf does so you can use that instead:
VB.NET:
If procname.IndexOf(string1, StringComparison.CurrentCultureIgnoreCase) <> -1 OrElse _
   procname.IndexOf(string2, StringComparison.CurrentCultureIgnoreCase) <> -1 OrElse _
   procname.IndexOf(string3, StringComparison.CurrentCultureIgnoreCase) <> -1 Then
    '...
End If
It's not as neat but it will do the job. Note also the use of OrElse rather that Or.
 
Back
Top