MSFN Forum: Looping TASKKILL - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Looping TASKKILL Rate Topic: -----

#1 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 31 August 2012 - 10:53 PM

Hi guys, i need to loop the taskkill command until the process is killed (this process is hard to kill :D). Starting from:

TASKKILL /F /IM process.exe /T


What is the easiest and effective way to do it? Thank you in advance! :hello:


#2 User is offline   tomasz86 

  • http://windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,241
  • Joined: 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

Posted 31 August 2012 - 11:43 PM

You didn't say which Windows is that.

This should work in 2000/XP/2003:

:TASKKILL
TASKKILL /F /IM process.exe /T
FOR /F %%I IN ('tasklist ^| FINDSTR/I "process.exe"') DO IF DEFINED %%I GOTO :TASKKILL


#3 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,750
  • Joined: 13-January 06

Posted 31 August 2012 - 11:49 PM

Killing the process one time should be enough even if it takes a long time so no need to loop on the taskkill step.
You need to first launch taskkill in another process using something like "start /high /separate".
Then you need to loop on tasklist until the process doesn't exist anymore:
:loop
rem ping -n 5 localhost
tasklist /fi  "IMAGENAME eq process.exe" |findstr /i process.exe
if %errorlevel% eq 0 goto loop else goto :next
:next


This code will work but it will also loop too fast and increase the load of the computer so i added a sleep (ping -n ) you should uncomment.

#4 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,356
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 01 September 2012 - 05:38 PM

Here is a vbs script that loops 12 times at 5 second intervals and if Notepad is open will closed it.
I have scripted this to run using Cscript.exe
Save As TaskKilllProcess.vbs
Dim C1, Obj,Task,Wmi
Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
'-> Make Sure It Runs Cscript
 If InStr(1,WScript.FullName,"cscript",1) Then
   TaskKill()
 Else
'-> Error Wrong Script Engine
  MsgBox _
  "This script was ment to run by this Scripting Engine Cscript.exe" & vbCrLf & _
  "Right Click this script and select either the Cscript or Cmd Promt", _
  4128,"Error Wrong Scripting Engine"
 End If
'-> Wait For Task Kill Process
  Function TaskKill()
   C1 = C1 + 1
   If Len(C1) = 1 Then C1 = "0" & C1 
    Do Until C1 = 12
'-> Name Of Process To Kill EG Notepad.exe    
     For Each Obj in Wmi.ExecQuery( _
     "Select * from Win32_Process Where Name = 'Notepad.exe'") 
      Obj.Terminate()
      WScript.Echo " Stopping : " & Obj.Name & vbCrLf 
      WScript.Sleep 500
     Next
      WScript.Echo " " & C1 & vbTab  & "Waiting For Notepad" & vbCrLf
      WScript.Sleep 5000 
     TaskKill() 
    Loop
   End Function 
'-> End Of Script Message
  WScript.Echo " " & C1 & vbTab  & "Exiting Script"
  WScript.Sleep 1000 



Rename TaskKilllProcess.vbs.txt to TaskKilllProcess.vbs to make active
Attached File  TaskKilllProcess.vbs.txt (1.07K)
Number of downloads: 1

#5 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 15 September 2012 - 03:40 AM

Thank you guys! :yes:

An other question... how can i convert a CMD batch file with more strings into a batch with a single string?

Could i have an example with this batch:

:loop
rem ping -n 5 localhost
tasklist /fi  "IMAGENAME eq process.exe" |findstr /i process.exe
if %errorlevel% eq 0 goto loop else goto :next
:next


Thank you!

#6 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,574
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 15 September 2012 - 10:28 AM

View Postallen2, on 31 August 2012 - 11:49 PM, said:

You need to first launch taskkill in another process using something like "start /high /separate".

Which still applies only to 16-bit programs.... :whistle:
http://ss64.com/nt/start.html
http://www.windowsne...emoryspace.html
http://www.microsoft...t.mspx?mfr=true

Quote

/separate : Starts 16-bit programs in a separate memory space.

jaclaz

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy