patilrahul2730 Valued Contributor.
Valued Contributor.
3160 views

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.