Page 1 of 1

Kill tasks by entering the task name/filter

Posted: 30 Mar 2012 05:43
by paul0
I try to write a script for the button but it fails to kill the process. Please point out if there is anything wrong.

Code: Select all

"Kill Task|%winsysdir%\imageres.dll /85"
  $task_name = input("Please enter a task to stop: ");
  if($task_name!="") {
    $task_to_kill = "$task_name" . "*";
    run 'cmd /c TASKKILL /F /IM "$task_to_kill"';
  }
  else {
    msg "The length of task name should > 0.";
  }
The script allow to kill a process, e.g. Firefox.exe, by entering a task name firefox.

Re: Allow user to enter the process to be kill

Posted: 30 Mar 2012 05:53
by Twisten
Wildcards for the /IM switch are only accepted with filters.
Could you try instead to use /FI "IMAGENAME eq firefox*" ?

Re: Allow user to enter the process to be kill

Posted: 30 Mar 2012 06:12
by paul0
Twisten wrote:Wildcards for the /IM switch are only accepted with filters.
Could you try instead to use /FI "IMAGENAME eq firefox*" ?
Thanks, Twisten.

The following line works in the command prompt.

Code: Select all

TASKKILL /F /IM firefox*

Re: Allow user to enter the process to be kill

Posted: 30 Mar 2012 06:14
by paul0
Twisten wrote:Could you try instead to use /FI "IMAGENAME eq firefox*" ?
I try to use the filter and the code is as follow:

Code: Select all

"Kill Task|%winsysdir%\imageres.dll /85"
  $task_name = input("Please enter a task name to stop: ");
  if($task_name!="") {
    $task_to_kill = "$task_name" . "*";
    run 'cmd /c TASKKILL /F /FI ""IMAGENAME eq $task_to_kill""';
  }
  else {
    msg "The length of task name should > 0.";
  }
It still has no luck. :?

Re: Kill tasks by entering the task name/filter

Posted: 30 Mar 2012 08:58
by Twisten
I would try stepping through it if i were you, and pay close attention on the last step as it might show you something about the quotes (I've done similar scripts the quoting can be tricky).

Re: Kill tasks by entering the task name/filter

Posted: 30 Mar 2012 09:29
by highend
Change:

Code: Select all

run 'cmd /c TASKKILL /F /FI ""IMAGENAME eq $task_to_kill""';
to:

Code: Select all

run "cmd /c TASKKILL /F /FI ""IMAGENAME eq $task_to_kill""";

Re: Kill tasks by entering the task name/filter

Posted: 30 Mar 2012 23:41
by paul0
Thanks, Twisten and Highend. :appl:

I already use the step mode and check the value of the variable, but I didn't notice the quote.