0

I have an issue with a program which sometimes doesn't quit correctly. I still working to fix it but I need a workaround to be able to kill the process for now.

Problem is that I can't kill it with the command like :

taskkill /PID <pid> /T /F

I have an error : "There is no running instance of the task"

However, it is possible to kill it by opening the task manager and stopping the process from here.

So I was wondering what command the task manager was sending to end the process which could be used in a script ? Or maybe another method ?

EDIT : picture of the problem

It is written in french, the translation is :

Error : process with PID 9664 <child of process with PID 4920> can't be stopped
Cause : There is no running instance of the task

cmd.exe image

Dinendal
  • 269
  • 1
  • 5
  • 19
  • 1
    Are you sure your PID is right? This message can only mean you got the wrong process ID. Can you show as an example how you call it, with an actual value? – CherryDT May 23 '16 at 12:02
  • Have you considered the obvious issue, that you are passing the wrong PID? Why do you assume that the *OS* is at fault? How did you find the PID ? – Panagiotis Kanavos May 23 '16 at 12:02
  • `Taskkill` works without problem if the correct PID is used. Is the process you are targeting actually running? Most likely it has already ended before you get to execute the command. Are you using a PID value stored earlier? – Panagiotis Kanavos May 23 '16 at 12:06
  • I have added a picture, even though it is written in french. The PID is the good one. The process is still in the tasklist but the application isn't running anymore because I quit it. But when I quit it I know that sometimes there is a crash of the application which seems to lead to that kind of problems. The crash is something related to the error : "cannot make qopenglcontext current in a different thread" that I working on at the moment as well – Dinendal May 23 '16 at 13:07

1 Answers1

1

vbscript.vbs

task="process.exe"
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & task & "'",,48) 
For Each objItem in colItems 
    'Wscript.Echo "-------------------------------------------"
    'Wscript.Echo "CommandLine: " & objItem.CommandLine
    'Wscript.Echo "Name: " & objItem.Name
    'Wscript.Echo "PID: " & objItem.ProcessId
    'Wscript.Echo "StartTime: " & objItem.CreationDate
    StartTime=objItem.CreationDate
    Y=Mid(StartTime,1,4)
    Mo=mid(StartTime,5,2)
    D=mid(StartTime,7,2)
    H=mid(StartTime,9,2)
    M=mid(StartTime,11,2)
    S=mid(StartTime,13,2)
    'Wscript.Echo M & "/" & D & "/" & Y & " " & H & ":" & M & ":" & S
    Q=Cdate(Mo & "/" & D & "/" & Y & " " & H & ":" & M & ":" & S)
    elapsed=DateDiff("s", Q, Now())
    'Wscript.Echo  Now() & vbtab & Q  & vbtab & elapsed
    'If process is older then 1 min then terminate
    If elapsed> 60 and lcase(objItem.Name) ="cscript.exe" then
        Wscript.Echo "Terminate:" & " " & objItem.CreationDate & " " & objItem.CommandLine
        objItem.Terminate()
    End if
Next