Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Looping TASKKILL

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
  • Joined 03-October 03
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:


How to remove advertisement from MSFN

#2
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#3
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,812 posts
  • Joined 13-January 06
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
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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
'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.
'-> This is only posted as example code and meant only to used as such.
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



GunSmokingMan



#5
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
  • Joined 03-October 03
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
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

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

jaclaz




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users