Batch Script doesn't close - batch-file

Before I get comments saying this is a duplicate, I looked, found similar questions but their respective answers didn't work for me.
I currently have a simple batch script to refresh explorer.exe (related to this question) and have exit at the end. The script works but the command window doesn't close. Looking at other questions, people had suggested using exit/b. Tried that as well and it had the same affect as the former.
My full code can be found in the link above but I will also post here.
#echo off
cls
taskkill /f /im explorer.exe >nul
timeout 1 /nobreak >nul
explorer.exe
exit

Use start explorer.exe so that explorer is launched on its own thread and not using the command window thread. As it is now, by just calling the application from the script, you are telling the command window to wait until explorer is exited before continuing.

Related

Taskkill batch file to close not responding apps closes an app that is working and responding

Sorry for the awfully worded title, I have a batch file that runs the command:
"taskkill.exe /F /FI "status eq NOT RESPONDING"
I then attached a shortcut of the file to my task bar so that whenever a program doesn't respond I have quick access to close it.
However, recently it has decided to start closing Discord, despite it responding normally at pretty much all times. I'm not sure why, can anyone help?
Apply a taskkill filter for WINDOWTITLE or IMAGENAME and use the not equal (ne) operator to exclude Discord.
Discord could be not responding at the moment you are running your script.

Stop execution of SQL query and kill ssms from a .bat file [duplicate]

This question already has answers here:
batchfile taskkill /IM cmd.exe not closing cmd.exe
(5 answers)
Closed 5 years ago.
Yesterday I did something bad. I left a SQL query running to see how long it would take, then promptly forgot about it. It got hung and run overnight, killing our production cycle.
In an effort to never have this happen again, I am trying to write a .bat file which runs at 1am to kill SSMS. Its a quick one-liner, but only works if nothing is running...defeating the purpose.
taskkill /IM Ssms.exe
Does anyone know a .bat command to force it to close? I was looking for a way to kill all of my queries, but am wondering if there was a better way to do it.
EDIT: I'm not set on a .bat file if there's another idea. Python in particular is another option.
As per this answer
You need to use the /f parameter so your command become
taskkill /f /IM Ssms.exe

How to close an invisible VBS file

I am trying to code a batch file that can play a song.
Luckily I found a solution to that at Stack Overflow. I used SachaDee's method, which created a VBS file that would play my mp3 file nicely.
My only issue is that once the VBS file is opened, I can't seem to find a way to stop the music. I even tried deleting the file in mid-song, but the song will still continue.
EDIT:
I found out that the way to solve this is by running the following command.
taskkill /IM wscript.exe /F
Just to end up the question.
taskkill /IM wscript.exe /F
This will stop wscript.exe with full force. However, a vbs can also be executed through cscript.exe.
According to this question, it seems to be ideal to use cscript for command-line, to execute VBS. Altough both works.
With your keyboard, press Ctrl+alt+del , then click Task Manager.
In task manager, click on the section where it shows you the programs that are running.
Find the VBS icon: A little cube with branches.
Click on the icon, then on the End Task Button.

Batch file to start browser minimized and kill it after

Trying to create a batch file that will open a specific browser (firefox) minimized and direct it to a link. After A specific period 5 seconds the browser will close. I can direct to the link open a specific browser but the browser does not start minimized nor does it close after 5.
#echo off
SET BROWSER=firefox.exe
SET WAIT_TIME=2
start /min %BROWSER% http://www.stackoverflow.com
SET WAIT_TIME=2
taskkill /IM firefox.exe
Your batch file cannot close the process because, while it sets a variable called WAIT_TIME, the batch file does not actually wait; the taskkill command runs immediately, before the process has even started. You need to add a command such as timeout to actually make the batch file wait.
SET WAIT_TIME=2
timeout %WAIT_TIME%
taskkill /im firefox.exe
For the minimized window, there is no good solution. A Windows (non-console) program receives the /min param through its nCmdShow parameter to WinMain(), but it's up to the program what to do with that. Most simply ignore it. There are 3rd-party solutions which will send a minimize command to the window after it has opened, but there's no easy way to do this in Windows Batch without involving another scripting language like VBS or PowerShell.

calc.exe file is not getting killed through batch file

I prepared one batch file to open calc.exe as a practice. I deleted the batch file accidentally. Now whenever I am closing the calc.exe application, every time it gets open after 10 seconds. Please help me.
in Task manager, kill the process conhost.exe (more details) or Windows command processor(fewer details) wherever you encounter it.
Hope that helped!
Use Process Explorer to see what process calc.exe was started by and prevent that for example by deleting its autorun.
Did you purposely start calculator 10 sec after it's been terminated in batch script? But doesn't seems like your deleted batch script is still running. Open cmd and type in taskkill /im "calc.exe", it should taskkill calculator, if it's not, comment below.

Resources