Unable to kill a process in Windows 8.1 through VBScript

Hello All,

I am using the below piece of code to terminate all the instances of the application for e.g.: notepad. But it is not getting executed in windows 8.1 (32 bit OS). It is working fine with Win7 (64 bit OS) and Win 10 (32 bit OS). Can some one please help me to get rid of this?

Analysis:

It was failing at line:  For Each objProcess  in colProcess

Even after introducing the line in the below code its failing: Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")

 

Code:

Function KillAll1(ProcessName)
    Dim objWMIServicde, colProcess
    Dim strComputer, strList, p
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name like '" & ProcessName & "'")
    For Each objProcess  in colProcess
       objProcess.Terminate             
    Next
End Function
  
KillAll1("notepad.exe")

 

Thanks in Advance,

Rahul