During a project it was required to do a forced de-installation of licensed software on the client machines. In order to do this we had to kill some running processes on the client machines. This, ofcourse, is a little ‘brute force’ and not very user friendly, but it was the only way to make sure that the software actually got de-installed.

A lot of running client applications used either Internet Explorer or FireFox as a prerequired / base application. To get a successful de-installation I made a script which closed all versions of these browsers right before the actual de-installation (otherwise, in quite some situations, the de-installation would fail).

The total ‘clean up’ script was a bit longer than what is posted, but this should give you an idea of what happens.

kill_process_ie_and_ff.vbs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Function KillProcess()
On Error Resume Next 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}" _ 
  & "!\\.\root\cimv2")
 
Set colProcess = objWMIService.ExecQuery ("Select * From Win32_Process")
For Each objProcess in colProcess
  If LCase(objProcess.Name) = LCase("firefox.exe") OR _ 
     LCase(objProcess.Name) = LCase("iexplore.exe") Then
    objWshShell.Run "TASKKILL /F /T /IM " & objProcess.Name, 0, False
    objProcess.Terminate()
    'MsgBox "- ACTION: " & objProcess.Name & " terminated"
  End If
Next
End Function

PS. The On Error Resume Next isn’t the most beautiful solution, but it is kind of ‘wanted’ in this situation. The script often found multiple instances of the same process running and gave an error when it got to the second (or third or …) loop, because it was already terminated. This could be done by some proper error handling, but in some cases I was just lazy ;)

  • Ali 6667254

    NOT WORKING