I am running a coded ui script in infinite loop as per my requirement. I can start the coded ui test using the the mstest.exe.
I wanted to know is there any way using which I can stop the coded Ui test, any command that I can use in the batch file to stop the coded ui script?
You can try this little batch to kill any process :
#echo off
Title Process Killer
Mode con cols=72 lines=5 & Color 0C
set Process2Kill=mstest.exe
Taskkill /IM "%Process2Kill%" /F
pause
And if you want to see more features like how to start a process and how to kill one process or multiple processes at once that interact with user input with a dynamic menu you should take a look at this post ==> How to check and correct user input when he omit the extension .exe to kill the process?
Related
I have 2 batch files (1.bat and 2.bat). I want 2.bat to run when 1.bat closes. Is that possible?
Or is there a way to close a batch file when a batch file closes. Here is my code which doesnt work:
cd C:\xampp
start apache_start.bat
cd C:\Users\MinecraftServer\Desktop\1.12.2MinecraftServer
MC1.12.2Start.bat
taskkill /F /IM cmd.exe /T
I have a minecraft server running with a .bat file and a web server running off of a .bat file (using xampp, its used for prtg monitorng).
start will create a completely independent process and continue immediately to your next batch command. That independent process may do a job and terminate, or may say open an application like notepad and wait until the notepad is closed. Regardless, a straight start command will not stop the batch that it is in - the next step will be executed, whether or not the process that has been started has terminated.
You can also add the /wait switch to start. If this switch is used, the batch will wait until the started process terminates.
Preferred syntax for start is
start /wait "window title" executable parameters...
where "window title" may be an empty, but not absent string. Including this as the first parameter is preferred because the first quoted string in a start command is used as a window title for the started process, and thus start may not act as expected where the executable or any of its parameters is quoted.
call executablename... will wait for that executable to terminate before progressing to the next step. This may or may not be what is desired.
MC1.12.2Start.bat in your code will SWITCH to that batch and remaining batch lines will be ignored.
Which may be fortunate in this case, since as you've coded it, the apache_start.bat may or may not have completed when the taskkill command is run, killing all cmd.exe sessions.
Hope I'm in the right place here, wasn't sure where to post and this seemed the most likely
I use a cmd box to run a serial flasher program for repairing wifi boards, the way it works is this.
open a command prompt and change to the working directory
enter the command
sfh_DM36x.exe -nandflash -v -p "COM3"
this starts the flashing program, however, due to the way it works, the program when finishing the first time just loops with bootme bootme, this is normal behavior.
Normally I just hit CTRL+C and exit the batch file.
The same command is run again and this time the flashing process completes and you are returned to the C:\ prompt.
Now you have the information here is what I am trying to achieve.
Launch a batch file that runs the runflash.bat, kill the runflash.bat and then run runflash.bat again.
So far I have gotten as far as this (start.bat)
start c:\users\jud\desktop\runflash.bat
timeout /t 5
This runs a new CMD prompt and opens the runflash.bat
I've then entered a timeout of 5 seconds (long enough for the first attempt to finish)
at this point, I wanted to kill the currently open CMD prompt and then execute runflash.bat again.
at this point I'm stumped, any attempt to kill the second CMD prompt just kills the original, I've looked at taskkill but the PID changes each time I run the script, as well as other suggestions I've come across during google searches, most just relate to killing batch files manually or killing a CMD prompt where a batch file has finished.
Can this be done, the idea is to pass the file out to users who aren't familiar with CMD prompt workings as an all in one solution.
Provide the new process with a unique title (see start /? - the first quoted parameter is set as a title). Takskkill can then identify and close the process with its title:
start "JudRunFlash" "c:\users\jud\desktop\runflash.bat"
timeout /t 5 >nul
taskkill /fi "WindowTitle eq JudRunFlash"
Solved
thank you so much for helping me Jean-François Fabre, haveing someone who was thinking along with me kept me motivated to keep figuring things out myself!
what i ended up doing is using a timer script, that first boots up the scanning script, after 900 seconds of pauze the timer proceeds to open a vbs script that closes cmd and opens the timer again to do another 15 minute loop.
how to close a batch file with another batch file
C:\pokemongo-api-demo-maps>taskkill timedlocator
ERROR: Invalid argument/option - 'timedlocator'.
Type "TASKKILL /?" for usage.
currently using a runner script that boots up the batch file every 15 Sec (testing)
it wont close the batch script however
ive tried
taskkill/im cmd.exe
and
taskkill/im timedlocator.bat
the timedlocator gives the error, and the cmd closes the runner script aswell
that needs to reboot it, i cant seem to shutdown a specific cmd window without closing the other one, one solution ive tried is to make this timer shutdown script VBS and use this to shutdown CMD all together before rebooting it, but i dont know anything about what commands to use in VBS
original post
so basically i have a script that scans a area in pokemon go, unfortunately its about as unstable as it gets, so to fix this i need to reboot it about every 15 minutes, ive already tried a few things but got stuck in the end because im not very familiar with coding,
the original boot script script:
#echo off
set /p UserInputPath= Set Location-
C:\Python27\python main.py -u name -p pass -l "%UserInputPath%"
this calls the actual program that does all the work, after some research i found this How do I create a batch file timer to execute / call another batch throughout the day
and added this into the start of the script
start timer.bat
this opens a 2nd script to close and reboot after a timer
TIMEOUT /T 15 /NOBREAK
taskkill timedlocator
start timedlocator.bat
this leaves me with 2 problems i have not been able to figure out
how do i close the first batch without closing the timer CMD? ive tried messing around with taskkill and closing cmd alltogether, but this makes it impossible to boot it again
how do i automatically input a fixed streetname into the first file?
i have tried to replace the userinputpath with the streetname but that didnt seem to work.
setlocation-
at which point you enter a streetname, it sends this to the locator and it starts working,
what im trying to achieve is bypassing this first step and always send the same name.
any help with this would be much appreciated, ive been messing around w this for about 2 hours now and i have made some progress but ive seemed hit a dead end here with my limited computerskills
not sure of you're asking, but I'll try to answer anyway:
how do i close the first batch without closing the timer CMD? ive tried messing around with taskkill and closing cmd alltogether, but this makes it impossible to boot it again
You're taking it the wrong way round: create a script called runner.bat for instance and put this (untested)
:loop
start timerlocator.bat
timeout /T 900 /NOBREAK
taskkill /F /IM "python.exe"
goto loop
Your main script is started in background, and is killed and relaunched every 15 minutes (your 15 value is wrong timeout needs seconds).
how do i automatically input a fixed streetname into the first file? i have tried to replace the userinputpath with the streetname but that didnt seem to work.
=> remove the /P option and set the real value.
set /p UserInputPath=type_your_value_here
I want to make a automated program in .bat. The program needs to run a command. However, the command must be run from a custom CMD.
If I open a regular CMD, the commands that I will do:
C:\Hardware\bin\StartCustomCMD.bat init (This is the first thing I will type. It starts the custom CMD.)
bb autobuild (This is the second thing that I will type. The command goes into the custom CMD)
You can probably tell that I did not write these scripts. I am trying to set this up in Windows Scheduler so that the script gets run automatically every day. Any help on how can I do that?
Thanks.
Make yourself a new batch file, and embed the other things into it, and then run that.
#echo off
call C:\Hardware\bin\StartCustomCMD.bat
bb autobuild
If bb it itself a batch file, then use call on it also. What call does is execute another batch file, and then continue processing. If you don't use call, when you run one batch file from another, the latter 'takes over' and the caller does not continue.
To do this you can use the timeout and goto command. Timeout waits a period of time in seconds but it can be skipped by pressing any key while cmd is open at the top layer. If you can see cmd press its icon on the desktop until you can not see it. Then using the goto command you can go to the top line. So here would be your script:
:start
C:\Hardware\bin\StartCustomCMD.bat init
bb autobuild
timeout 86400
goto start
You already know what the first two commands do, but timeout 86400 waits exactly one day then the goto start command goes to the first command so that gets repeated. If you need to add any more commands then put them above the timeout 86400 command.
This is sort of a follow-up to my question earlier (link).
To test things out I made this simple batch file to ensure the Task Scheduler was properly executing the batch file:
cd "C:\Users\user\Desktop"
echo. 2>test.txt
So after the test.txt document is created on the desktop, the batch file should end but it continues to run:
Is there a way, either at the end of the batch file or a setting in the Task's Properties, to ensure that the cmd process quits?
Thanks!
I ran into the exact same problem. However, I felt duped when I read what Trevor778 wrote in this post:
I had the same problem - the task worked but the status kept showing Running. One simple thing to try is click on the Task Scheduler Library in the left column. Click Action/Refresh. Presto. Status changed to Ready. That's all it was for me, the task ran fine, just the status didn't update. Hope this helps.
ref: https://social.technet.microsoft.com/Forums/en-US/2f6dc29c-3b8b-45f5-a2a7-53e076acc062/task-scheduler-scheduler-status-is-being-running-always?forum=winservergen
you can add "exit" to last line of your script
cd "C:\Users\user\Desktop"
echo. 2>test.txt
exit
Running TASKKILL /F /IM cmd.exe will kill all cmd.exe processes whether it was the one that spawned this batch file or not. That's probably not desirable behavior. :-)
Judging by your last question, I'm guessing you're still running your task with cmd.exe /k, which will keep that window open indefinitely. For an unattended task, cmd.exe /c is a better choice. When the batch file finishes, the process should end.
Same here on Windows 7.
Putting all batch files in a directory in the user User specific path who runs the task
run programm = " cmd.exe " (without a path)
Your extras, mine where = " /c "C:\Users[username]\whatever\your_batchfile.bat" >> log.txt" "
" >> log.txt " so that i can see the output of the batch...
start in = " C:\Users[username]\whatever "
I also checked the "run with highest privilges" box
after that everything worked fine :)
Use following
exit /B
you may find more information in windows console area then type:exit/?
I know it's an old question, but I personally found that if I let a pause at the end of the bat file, it would keep the status as "Running".
I usually leave a pause at the end to help with debugging, but I found when I removed it, the task scheduler finally recognised it as having exited. It didn't help if I just refreshed it.
The solution I found was to add this line at the very end of the batch file:
TASKKILL /F /IM cmd.exe
Now after the batch file task runs and completes, it is no longer in the All Running Tasks list and the status goes back to 'Ready' instead of staying at 'Running'.
Warning:
That command will kill all running command processor instances so it may be potentially harmful!