Caml Light Posted September 1, 2012 Share Posted September 1, 2012 Hi guys, i need to loop the taskkill command until the process is killed (this process is hard to kill ). Starting from:TASKKILL /F /IM process.exe /TWhat is the easiest and effective way to do it? Thank you in advance! Link to comment Share on other sites More sharing options...
tomasz86 Posted September 1, 2012 Share Posted September 1, 2012 You didn't say which Windows is that.This should work in 2000/XP/2003::TASKKILLTASKKILL /F /IM process.exe /TFOR /F %%I IN ('tasklist ^| FINDSTR/I "process.exe"') DO IF DEFINED %%I GOTO :TASKKILL Link to comment Share on other sites More sharing options...
allen2 Posted September 1, 2012 Share Posted September 1, 2012 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::looprem ping -n 5 localhosttasklist /fi "IMAGENAME eq process.exe" |findstr /i process.exeif %errorlevel% eq 0 goto loop else goto :next:nextThis 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. Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 1, 2012 Share Posted September 1, 2012 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.exeSave 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 Link to comment Share on other sites More sharing options...
Caml Light Posted September 15, 2012 Author Share Posted September 15, 2012 Thank you guys! 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::looprem ping -n 5 localhosttasklist /fi "IMAGENAME eq process.exe" |findstr /i process.exeif %errorlevel% eq 0 goto loop else goto :next:nextThank you! Link to comment Share on other sites More sharing options...
jaclaz Posted September 15, 2012 Share Posted September 15, 2012 You need to first launch taskkill in another process using something like "start /high /separate".Which still applies only to 16-bit programs.... http://ss64.com/nt/start.htmlhttp://www.windowsnetworking.com/kbase/WindowsTips/WindowsNT/AdminTips/Miscellaneous/Running16-bitprogramsinseparatememoryspace.htmlhttp://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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now