We help IT Professionals succeed at work.

why this script works in case of iexplore, but this doesn't work in case of javaw.exe?

shouichi
shouichi asked
on
Following script is to kill the process.
i want to know the reason why this script works in case of iexplore, but this doesn't work in case of javaw.exe

1)processName = "iexplore.exe"
this script works fine and IE can finish by using this script.
However,
in case of
2)processName = "javaw.exe"
This script doesn't work and I can't terminate the process.

Please let me know the reason why I can't kill the javaw.exe ?


'Object creation
Set objLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer


'Specify the process to kill
processName = "javaw.exe"


'Display message to ask confirmation

strMsg = processName & "  is OK to be killed ?"
Set objShell   = WScript.CreateObject("WScript.Shell")
rc = objShell.Popup(strMsg, 10,, vbOkCancel)

If rc = vbCancel Then
      Wscript.echo "Cancelled to kill the process"
      Wscript.Quit
ElseIf rc = vbTimeOut Then
      Wscript.echo "Killing the process is cancelled"
      Wscript.Quit
ElseIf rc = vbOK Then
      Set colProcSet = objService.ExecQuery("Select * From Win32_Process Where Caption='" & processName & "'")
      For Each objProc In colProcSet
            objProc.Terminate
      Next
End If


'Kill the process
i = 10
Do
      strTmp = ""
      Set colProcSet = objService.ExecQuery("Select * From Win32_Process Where Caption='" & processName & "'")
      
      For Each objProc In colProcSet
            strTmp = objProc.Name
      Next
      
      If strTmp <> "" Then
            i = i - 1
            If i = 0 Then
                  Wscript.echo processName & "failed to kill the process."
                  Wscript.Quit
            End If
            Wscript.Sleep 500
      Else
            Exit Do
      End If
Loop

Wscript.echo processName & "end"
Comment
Watch Question

can you kill the javaw.exe from the task-manager?
is that going-out of the process list or re-appearing again?