Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Caml Light

Looping TASKKILL

6 posts in this topic

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:

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

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
0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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

0

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.