How to Use Batch File to Start and Stop the exe

In this blog, you will learn how to create your batch file to start and stop the exe and also how to check that file is exist or not.

If you want to create your bat file to start and stop the exe then write your logic on notepad and save it "batchname.bat" and to start an exe file from a batch file in Windows, start command is used for starting the exe from batch.

For example, to start the notepad you can use following command.

START C:\Windows\NOTEPAD.EXE

Here is an all batch file solution (a variation of my other answer) that will zip a file named c:\ue_english.txt and put it in C:\someArchive.zip.

  1. set FILETOZIP=c:\ue_english.txt    
  2.   
  3.     set TEMPDIR=C:\temp738  
  4.     rmdir %TEMPDIR%  
  5.     mkdir %TEMPDIR%  
  6.     xcopy /s %FILETOZIP% %TEMPDIR%  
  7.     
  8.     echo Set objArgs = WScript.Arguments > _zipIt.vbs  
  9.     echo InputFolder = objArgs(0) >> _zipIt.vbs  
  10.     echo ZipFile = objArgs(1) >> _zipIt.vbs  
  11.     echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs  
  12.     echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs  
  13.     echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs  
  14.     echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs  
  15.     echo wScript.Sleep 2000 >> _zipIt.vbs  
  16.     CScript  _zipIt.vbs  %TEMPDIR%  C:\someArchive.zip  
  17.   
  18.     pause  

You can use 'taskkill to kill the process. With the /IM parameter, you can specify image names. 

Example: 
  1. taskkill /im somecorporateprocess.exe  

You can also do this to 'force' kill, 

  1. taskkill /f /im somecorporateprocess.exe  

Hope you enjoyed this blog. Thanks for reading.

Ebook Download
View all
Learn
View all