Kill Batch fill process from another batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Kill Batch fill process from another batch file

#1 Post by mohdfraz » 24 Jan 2015 05:30

Hi,

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

Thanks

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Kill Batch fill process from another batch file

#2 Post by npocmaka_ » 24 Jan 2015 06:42

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 :?:

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Kill Batch fill process from another batch file

#3 Post by mohdfraz » 26 Jan 2015 08:29

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

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Kill Batch fill process from another batch file

#4 Post by Hackoo » 28 Jan 2015 05:54

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
'**********************************************************************************************

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Kill Batch fill process from another batch file

#5 Post by mohdfraz » 28 Jan 2015 07:39

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

Post Reply