Assistance needed with VBScript Process Termination

Hello,

I'm using VBScript to terminate processes for a software deployment. We haven't yet converted to Powershell. I've been running into issues with Internet Explorer. The script will run once through, close internet explorer and any other processes, but then it loops back through again and throws an error on line 7, Char 4. Error: Not Found, Code: 80041002, Source: SWbemObjectEX

I'm not certain why it's throwing the error with IE when there are no running processes, but I suspect it has something to do with the browser tabs.

The only way I've been able to get around this is by using "on error resume next"

I'm hoping someone has a suggestion on how to overcome this without using "on error resume next"

1 Function stopApps(strProcessName)
2    'on error resume next
3	set colProcesses = GetObject("winmgmts:\\.\root\cimv2")_
4	.ExecQuery("Select * from Win32_Process Where Name='" & strProcessName & "'")
5	for each objProcess in colProcesses
6		if colProcesses.count <> 0 then
7			objProcess.Terminate() 
8		end if
9	next	
10 end Function
11
12 stopApps "notepad.exe"
13 stopApps "iexplore.exe"


July 8th, 2015 5:25pm

You could also use taskkill.exe like so:

TASKKILL /IM notepad.exe /F

Run TASKKILL /? in Command Prompt for more information.

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 5:30pm

Terminating one IE will terminate all. THe same is not true of notepad.
July 8th, 2015 6:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics