The problem is the following line:
If InStr(1,Ucase(objItem.Name),Appname) >= 1 Then
Here you convert the property value Win32_Process.Nameto uppercase, but not convert Appnameto uppercase. By default, it InStrperforms case-sensitive searches, so if the input lines are the same but different from each other, you won’t get a match.
, Appname :
If InStr(1, UCase(objItem.Name), UCase(Appname)) >= 1 Then
vbTextCompare, :
If InStr(1, objItem.Name, Appname, vbTextCompare) >= 1 Then
, :
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process WHERE Name='" & Appname & "'", , 48)