What's new

.NET Help

  • Thread starter allensmith
  • Start date
  • Views 242
A

allensmith

Newbie
Messages
1
Reaction score
1
I have a program written in VB.NET and i want the program to auto-update. I've tried a few methods but without success. How do i make a second .exe file that will launch with the program itself on start to check if there is a new version and if there is download and overwrite current program, else just load the program as usual?
 
Im4eversmart

Im4eversmart

The hacks are real
Glitcher Modder Programmer
Messages
2,161
Reaction score
1,903
Auto-updating isn't usually done with two executables.

A simple way to do it is add a properties file, include the version number as a property, then when you application reads the property file, check online to see if the version number is the latest.

The program can then be updated by downloading the new exe file, find the current directory the program is running in, delete the file, then create the new exe in the same directory. You can then proceed to relaunch the exe, and force close the current instance of the app using system commands.
 
MatthewH

MatthewH

Member
Bright Idea Programmer Experienced Veteran
Messages
1,604
Reaction score
629
Auto-updating isn't usually done with two executables.

A simple way to do it is add a properties file, include the version number as a property, then when you application reads the property file, check online to see if the version number is the latest.

The program can then be updated by downloading the new exe file, find the current directory the program is running in, delete the file, then create the new exe in the same directory. You can then proceed to relaunch the exe, and force close the current instance of the app using system commands.
I would never do it like that simply because of errors I've encountered with it. I tried it like that and mid update it crashed because it couldn't overwrite anything because it was currently being used. That's why I will always use and updater that I create for each project to handle. And what if there's other dependencies? I usually will just download the zip archive and unzip it overwriting all the other files if they exist.

To the OP, here's what I would do personally and what I actually do in my programs now. Get a JSON file from the web, parse it, grab the version. Compare that version with the current and if it's less, show a popup notification saying there's a new update available and gives them the YesNo option. If yes, run the updater. If no, just exit the notification. That's it.
 
DaftHacker

DaftHacker

Jet fuel can't melt steel beams
Programmer Forum Addict Fabled Veteran
Messages
2,604
Reaction score
917
First you'll want to make a file on dropbox or whatever and then get the direct link.
The file will only contain something like: 1.0.0.0

On your main program in order:
>Delete the update exe if it exists so when you start your program again it will clear it away.
>Download your version file as string then compare it with your version.
>Ask user to update if your local version and downloaded version is different.
>If they decide to download the update, download the second program which will be your update exe.
>Start the update exe and close the current program.

On your update exe in order:
>Make sure all processes by the name of your main exe are closed.
>If the main program exists then delete it.
>Download the updated main exe.
>if main program exists then start it.
>once launched your main program will now delete the update exe.

That's the way i do it in C# and it works perfectly.
 
Im4eversmart

Im4eversmart

The hacks are real
Glitcher Modder Programmer
Messages
2,161
Reaction score
1,903
I would never do it like that simply because of errors I've encountered with it. I tried it like that and mid update it crashed because it couldn't overwrite anything because it was currently being used. That's why I will always use and updater that I create for each project to handle. And what if there's other dependencies? I usually will just download the zip archive and unzip it overwriting all the other files if they exist.

To the OP, here's what I would do personally and what I actually do in my programs now. Get a JSON file from the web, parse it, grab the version. Compare that version with the current and if it's less, show a popup notification saying there's a new update available and gives them the YesNo option. If yes, run the updater. If no, just exit the notification. That's it.

Code to delete current running exe:
Code:
ProcessStartInfo Info=new ProcessStartInfo();
Info.Arguments="/C choice /C Y /N /D Y /T 3 & Del "+
               Application.ExecutablePath;
Info.WindowStyle=ProcessWindowStyle.Hidden;
Info.CreateNoWindow=true;
Info.FileName="cmd.exe";
Process.Start(Info);

The idea is to use cmd for deletion, instead of another exe.
 
Skye20

Skye20

Newbie
Messages
12
Reaction score
7
I've done this.. Simplest way to do it.. You would want to have a text file uploaded somewhere. On start, download the text file. Inside the text file is a version number and a download link. Compare the version number with the current version then if it doesn't match then use the download link and download the file to the current folder. After that you will need to start another program to perform the renewal process of the main executable and associated files.
 
Top Bottom