how to kill opened apps using batchfile? - batch-file

I wanted to close opened app by running a batchfile code . My current code does not work and just freezes all black.
Code
#echo off
echo closing all programs...
taskkill /f /t /im explorer.exe
explorer.exe

I think taskkill /f /im explorer.exe should work oh and you should do pause or pause >nul at the end of the script else your program won't start also explorer.exe at the end of your script is not needed.

Related

Bat script to run commands in a running cmd

I use a windows .bat script to start all of my game servers
The script looks like this:
cd "C:\Users\Administrator\Desktop"
start Minecraft_HUB
start Minecraft_LOBBY
start Minecraft_SURVIVAL
with many more servers
It works for launching all of them at the same time but I need to manually type stop / exit in every single one to shut them down.
Is there any way I could have a .bat script that would insert and run a save & shut down command in a running cmd console?
I don't yet know how to make that script
From the prompt:
for /f "tokens=1,2delims=," %b in ('tasklist /fo csv') do echo %~b|find /i "minecraft">nul&if not errorlevel 1 echo taskkill /pid %~c
As a batch-file line:
for /f "tokens=1,2delims=," %%b in ('tasklist /fo csv') do echo %%~b|find /i "minecraft">nul&if not errorlevel 1 echo taskkill /pid %%~c
Note that the taskkill command will merely be echoed to the console. Remove the echo before the taskkill to actually execute the taskkill
Untested. Use at your own risk.

Taskkill no longer works with VLC

I have a batch that used to kill VLC.
echo
rem choice /c YN /n /d Y /t 120
taskkill /im vlc.exe
Now when it runs, VLC stays open, even though the CMD reports the taskkill command was successfully sent.
Any ideas? Perhaps a VLC (currently 2.1.5) update make it no longer work.
Is taskkill /im vlc.exe /f or taskkill /im vlc.exe /t /f working for you? Had the same problem with explorer.exe a while ago...

Taskkill and timer in batch

I currently have this batch script:
start udp%1.exe
timeout /t %2
taskkill /f /im "udp%1.exe"
This works great and kills the program after a selected amount of time, however if I was to manually close udp%1.exe and start another one with the same ID the timer from the other batch script is still running and will kill the next launched. I'm not entirely sure if I can check if the process is still running in batch? and if so to close the timer so it doesn't kill others with the same ID?
Try this code:
#echo off
start "udp%1.exe"
timeout /t %2
tasklist /FI "IMAGENAME eq udp%1.exe" 2>NUL | find /I /N "udp%1.exe">NUL
if "%ERRORLEVEL%"=="0" goto yes
goto no
:yes
taskkill /f /im "udp%1.exe"
exit
:no
exit
It waits the selected amount of time and if the program is running, it closes it, and if the program is not running, it exits. If you wan't to detect if the program is closed while the timer is still running, you might want to look into vbs scripts. :)

I want to run and kill a process with same batch file

I have bitlord I want this program to run when i click a batch file and when i don't want this program to run i want to kill it with same batch file. Can anyone please write the script Thanks a lot for giving your time.
I tried it scripting but failed.
If bitlord is not running then this will launch it
If bitlord is running then this will kill it
Change line 2 and line 3 to set the program name and path.
#echo off
set "program=bitlord.exe"
set "folder=c:\program files\bitlord"
tasklist |find /i "%program%" >nul || start "" "%folder%\%program%" & goto :EOF
tasklist |find /i "%program%" >nul && taskkill /f /im "%program%" & goto :EOF
Okay. I think i understand your question now:
#echo off
taskkill.exe /f /im notepad.exe
start calc.exe
The magic is to use the start command which starts a new command asynchronous. Meaning, it doesn't wait for the termination.

How to write a batch file which kill multiple process

I want a batch file that will kill all of chrome.exe process. I came across with this sample:
taskkill /im chrome.exe
which kill only the first process of chrome.exe that it find. how can I loop it?
You can use this:
taskkill /F /IM <processname.exe> /T
taskkill /F /IM Chrome.exe /T

Resources