# .bat file to restart application

**URL:** <https://forum.xojo.com/t/bat-file-to-restart-application/66434>\
**Category:** Windows\
**Created:** [November 3, 2021, 12:30pm UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434 "2021-11-03T12:30:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Govind\_Sankar\_Madhavan\_Pillai](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/b3f665/32.png) [@Govind\_Sankar\_Madhavan\_Pillai](https://forum.xojo.com/u/Govind_Sankar_Madhavan_Pillai)\
**Post date:** [November 3, 2021, 12:30pm UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/1 "2021-11-03T12:30:58Z")

</div>

Hi,

I have a .bat file that restarts an application. I checked the program and understood it. Its like this  
taskkill /f /im ApplicationName\_V1.1.5.exe  
timeout /t 1  
start K:…\ApplicationName\_V1.1.5.exe  
exit  
This program existed in the application folder for a long time and I have never checked it but now I checked it. But the thing is the application name has the version number attached to it which I change in the original application every time i make a change. But I see that is automatically changed here in this .bat file as well. I have not done any change to the program written in the .bat file. So how does it automatically change. Because I need to write a program like this for a new application where updates happen regulary but the .bat file should automatically change the application name. How do I do that. Kindly help me. Thank You.

Govind

---

<div class="post-metadata">

**Author:** ![Eric\_Bloom](https://forum.xojo.com/user_avatar/forum.xojo.com/eric_bloom/32/716_2.png) [@Eric\_Bloom](https://forum.xojo.com/u/Eric_Bloom)\
**Post date:** [November 3, 2021, 2:00pm UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/2 "2021-11-03T14:00:16Z")

</div>

I’m not sure I understand your question …

Are you asking about a procedure that updates or replaces the .bat file automatically? Maybe something in the application does this? Probably won’t work (permission denied) if the application lives in the Program Files folder.

The .bat file could be installed with the application .exe by your installer. You provide the correct .bat file when you build your installer.

Also I’m curious why you would need to restart the application. Might make sense to have this for a service application that might need a restart every once in a while.

---

<div class="post-metadata">

**Author:** ![Govind\_Sankar\_Madhavan\_Pillai](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/b3f665/32.png) [@Govind\_Sankar\_Madhavan\_Pillai](https://forum.xojo.com/u/Govind_Sankar_Madhavan_Pillai)\
**Post date:** [November 4, 2021, 7:11am UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/3 "2021-11-04T07:11:50Z")

</div>

The application is a test software. After testing one microcontroller, the application asks the user whether user needs to test another one. If the user says no, the application closes. If the user says test another then the application will run the .bat file which will then restart the application. Now the thing is both the application and the ,bat file was done by my predecessor and till now I have not made any changes to the .bat file. But I have made lots of changes to application, when I started the version was 1.0.0 and now its 1.1.5 and as you can see the version number is included in the file name. I checked the .bat file and in it it says V1.1.5 but when my predecessor wrote it, it must have been V1.0.0 and I have not changed it. Then how did it change to V1.1.5 automatically. This is my doubt.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [November 4, 2021, 7:32am UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/4 "2021-11-04T07:32:02Z")

</div>

There must be a build script that creates the .bat file. Check there.

---

<div class="post-metadata">

**Author:** ![anon20074439](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@anon20074439](https://forum.xojo.com/u/anon20074439)\
**Post date:** [November 4, 2021, 8:06am UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/5 "2021-11-04T08:06:10Z")

</div>

This should kill all versions of your application found in the current folder and start the one with the highest version number in the current folder:

```auto
@echo off
FOR /f "tokens=*" %%G IN ('dir /o-n /b ApplicationName_V*.exe') DO (
taskkill /f /im %%G )

timeout /t 1

FOR /f "tokens=*" %%G IN ('dir /o-n /b ApplicationName_V*.exe') DO (
start %%G
GOTO :eof )

```

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [November 4, 2021, 5:06pm UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/6 "2021-11-04T17:06:49Z")

</div>

> [@Govind\_Sankar\_Madhavan\_Pillai](#):
>
> If the user says test another then the application will run the .bat file which will then restart the application.

Wouldn’t it be best to use the Xojo’s Open command, then? (app.ExecutableFile.Open).  
You’d then have control right into Xojo to find which executable is the most recent one.

---

<div class="post-metadata">

**Author:** ![Eric\_Bloom](https://forum.xojo.com/user_avatar/forum.xojo.com/eric_bloom/32/716_2.png) [@Eric\_Bloom](https://forum.xojo.com/u/Eric_Bloom)\
**Post date:** [November 5, 2021, 11:57am UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/7 "2021-11-05T11:57:45Z")

</div>

Another thought … add a function within the application to reset itself so it doesn’t need to exit. This could eliminate the need to the external script.

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [November 5, 2021, 12:16pm UTC](https://forum.xojo.com/t/bat-file-to-restart-application/66434/8 "2021-11-05T12:16:10Z")

</div>

I also think this would be the safer way, because futures OS may prevent such a behaviour.
