Finish process and open again by . bat

Asked

Viewed 3,180 times

3

My problem currently is the following, I have an executable that has the function of employee access control, but due to some problem in this process it usually stops responding, with this I built a bat to finish the process, however, it is necessary to click on bat wait for it to complete and after that reopened the control executable.

I wanted an idea of how to create a bat end the process and after that open the executable again, this is possible?

.bat:

taskkill /f /im ACCA.exe

Path of the executable:

c:\exe\ACCA.exe

Thanks in advance for any help,

  • If you put one below the other in the same bat doesn’t work?

  • @Wictorchaves already tried it just doesn’t open, it seems that it only runs the first line.

  • If you need to restart it probably it is not responsive... after Kill, how long it takes to die?

  • @Bulfaitelo I’m waiting for you in chat...

2 answers

4

You have already put the necessary command to finish the program, which is the taskkill, now just missing by a start before the file path to boot it again.

Your batch would look like this:

taskkill /f /im ACCA.exe
start c:\exe\ACCA.exe

If you want it to wait a few seconds before starting the program you can put the command timeout /t 10 (to wait 10 seconds), in which case the batch would look like this:

taskkill /f /im ACCA.exe
timeout /t 10
start c:\exe\ACCA.exe

Save this as [filename]. bat and put it to a scheduled task on Windows.

  • Laércio thanks for the answer, but is falling into the same problem when starting the executable.

  • When the path has spaces you should put it between quotes, example: start "C:\ASC Solutions\ACCA\ACCA.exe"

  • ended up moving to a directory without spaces: https://i.stack.Imgur.com/Hk41r.png

  • Can you see the error that gives? Put the command pause at the end of the file to see what the error, the bat is saved in C: if it is not have to put C: at the beginning of batch.

  • I called the bat for the terminal it simply does not error but does not start https://i.stack.Imgur.com/2wca8.png

  • See the task manager if it is open.

Show 1 more comment

4


Execute the following code bat:

taskkill /F /IM ACCA.exe
ping 127.0.0.1 -n 10
start c:\exe\ACCA.exe

The ping serves as a sleep( I did not find the function of Sleep in the bat) for some cases of applications that are heavy and need a certain time to finish all their services, the parameter -n 10 indicates that the system should ping the ip(you can use another ip) an amount of 10 times before opening the executable again.

@Edited

I used the command timeout /t 10 quoted in the reply edited of Laércio to replace the command ping(used only for waiting for the full completion of the desired application) and worked, you can replace the line ping 127.0.0.1 -n 10 by command timeout /t 10 In case you want to wait 10 seconds (besides that you can end the waiting by pressing any key), rasoável time to my view to finish any application. I recommend using the timeout, since the ping was not actually done to pause the execution. It is up to you to use the ping or the timeout.

Note: I don’t know why, but in talking to Bulfaitelo in Chat, we saw that when creating an executable Shortcut c:\ACCA\ACCA.exe and add the path of this shortcut to the command start, the command worked as expected.

  • using this bat, it executes the first line but in the second it error and in the third it does not find the file see the error screen: https://i.stack.Imgur.com/n58CB.png

  • Removes the * , I put only to signal and explain in the text. I will edit the question.

  • tried it finishes does the ping but the star does not start the application, I realized that the error of not finding is due to the spacing of the directory, it seems that calling for start C:\acca... it does not start the https://i.stack.Imgur.com/kD5l9.png executable

  • In your directory C:\ACCA there is actually an executable called ACCA.exe ? Because, as I understood in your question, this executable is in the following directory: c:\exe\ACCA.exe

  • Surely it is at this point that it does not work I created a bat only with the c:\ACCA\ACCA.exeit simply does not start the executable, if I go in the shortcut no more parameter is passed, and if it is directly in the executable and click it starts normally

  • Make sure your executable is really in the directory c:\acca or c:\exe.

  • Yes https://i.stack.Imgur.com/Hk41r.png

  • If you’re in the C:\ACCA, I will edit your question. Please accept it.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.