.bat file to restart application


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
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.


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.

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.

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

1 Like

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:

@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 )
1 Like

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.

1 Like

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.

1 Like

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