Kill tasks by entering the task name/filter

Discuss and share scripts and script files...
Post Reply
paul0
Posts: 137
Joined: 23 Oct 2009 19:26

Kill tasks by entering the task name/filter

Post 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.
Last edited by paul0 on 30 Mar 2012 07:24, edited 2 times in total.

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

Re: Allow user to enter the process to be kill

Post by Twisten »

Wildcards for the /IM switch are only accepted with filters.
Could you try instead to use /FI "IMAGENAME eq firefox*" ?

paul0
Posts: 137
Joined: 23 Oct 2009 19:26

Re: Allow user to enter the process to be kill

Post 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*
Last edited by paul0 on 30 Mar 2012 06:39, edited 1 time in total.

paul0
Posts: 137
Joined: 23 Oct 2009 19:26

Re: Allow user to enter the process to be kill

Post 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. :?

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

Re: Kill tasks by entering the task name/filter

Post 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).

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Kill tasks by entering the task name/filter

Post 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""";
One of my scripts helped you out? Please donate via Paypal

paul0
Posts: 137
Joined: 23 Oct 2009 19:26

Re: Kill tasks by entering the task name/filter

Post 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.

Post Reply