Page 1 of 1

Kill Batch fill process from another batch file

Posted: 24 Jan 2015 05:30
by mohdfraz
Hi,

I want to kill the running batch file process with another batch file.

Thanks

Re: Kill Batch fill process from another batch file

Posted: 24 Jan 2015 06:42
by npocmaka_
One possible way is by getting the batch file PID - viewtopic.php?f=3&t=6133
save it to temp file and then kill it from another batch :?:

Re: Kill Batch fill process from another batch file

Posted: 26 Jan 2015 08:29
by mohdfraz
npocmaka_ wrote:One possible way is by getting the batch file PID - viewtopic.php?f=3&t=6133
save it to temp file and then kill it from another batch :?:



Ok Thanks

Re: Kill Batch fill process from another batch file

Posted: 28 Jan 2015 05:54
by Hackoo
Hi :)
You can also give a try with this vbscript

Code: Select all

Option Explicit
Call KillProcessbyName("MyBatchFileName.bat")
'**********************************************************************************************
Sub KillProcessbyName(FileName)
   On Error Resume Next
   Dim WshShell,strComputer,objWMIService,colProcesses,objProcess
   Set WshShell = CreateObject("Wscript.Shell")
   strComputer = "."
   Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
   For Each objProcess in colProcesses
      If InStr(objProcess.CommandLine,FileName) > 0 Then
         If Err <> 0 Then
            MsgBox Err.Description,VbCritical,Err.Description
         Else
            objProcess.Terminate(0)
         End if
      End If
   Next
End Sub
'**********************************************************************************************

Re: Kill Batch fill process from another batch file

Posted: 28 Jan 2015 07:39
by mohdfraz
Hackoo wrote:Hi :)
You can also give a try with this vbscript

Code: Select all

Option Explicit
Call KillProcessbyName("MyBatchFileName.bat")
'**********************************************************************************************
Sub KillProcessbyName(FileName)
   On Error Resume Next
   Dim WshShell,strComputer,objWMIService,colProcesses,objProcess
   Set WshShell = CreateObject("Wscript.Shell")
   strComputer = "."
   Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
   For Each objProcess in colProcesses
      If InStr(objProcess.CommandLine,FileName) > 0 Then
         If Err <> 0 Then
            MsgBox Err.Description,VbCritical,Err.Description
         Else
            objProcess.Terminate(0)
         End if
      End If
   Next
End Sub
'**********************************************************************************************



Thank you.

I have added this Check line in my batch file. Then I create the killmonitoring.txt file from another batch file if require and eventually my first batch file check it and exit the run nicely.

Code: Select all

if exist KillMonitoring.txt (exit)



Thanks