Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 

Recommended Posts

Caml Light    0

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:

Share this post


Link to post
Share on other sites
tomasz86    68

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

Share this post


Link to post
Share on other sites
allen2    1

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.

Share this post


Link to post
Share on other sites

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,WmiSet Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")'-> Make Sure It Runs CscriptIf InStr(1,WScript.FullName,"cscript",1) ThenTaskKill()Else'-> Error Wrong Script EngineMsgBox _"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 ProcessFunction TaskKill()C1 = C1 + 1If Len(C1) = 1 Then C1 = "0" & C1Do Until C1 = 12'-> Name Of Process To Kill EG Notepad.exeFor Each Obj in Wmi.ExecQuery( _"Select * from Win32_Process Where Name = 'Notepad.exe'")Obj.Terminate()WScript.Echo " Stopping : " & Obj.Name & vbCrLfWScript.Sleep 500NextWScript.Echo " " & C1 & vbTab & "Waiting For Notepad" & vbCrLfWScript.Sleep 5000TaskKill()LoopEnd Function'-> End Of Script MessageWScript.Echo " " & C1 & vbTab & "Exiting Script"WScript.Sleep 1000

Share this post


Link to post
Share on other sites
Caml Light    0

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!

Share this post


Link to post
Share on other sites
jaclaz    926

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.windowsnetworking.com/kbase/WindowsTips/WindowsNT/AdminTips/Miscellaneous/Running16-bitprogramsinseparatememoryspace.html

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx?mfr=true

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

jaclaz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×