Ich stand letztens auch vor dieser Frage.
Ich habe es mir relativ einfach gemacht.
1. Programm Starten und Version über DownloadString prüfen.
Die neue Version kannst du in eine .txt Datei schreiben.
Beispiel:
Code:
Code:
static string VERSIONS_CHECK = "http://DeineDomainOderFTP/version.txt";
static string Reply;
static string Version = "1.0.0";
static string NEW_VERSION = "http://DeineDomainOderFTP/NEW.exe";
static string UPDATE_FOUND = "Update available! \nDo you want to download the update now ?";
static string UPDATE_READY = "New version has been downloaded. \nDo you want to start the new version now ?";
private void CheckUpdate()
{
WebClient DownloadString = new WebClient();
Reply = DownloadString.DownloadString(new Uri(VERSIONS_CHECK));
if(Reply == Version)
{
return;
}
else
{
var result = MessageBox.Show(UPDATE_FOUND, "", MessageBoxButtons.OKCancel);
if (result == System.Windows.Forms.DialogResult.OK)
{
DownloadString.DownloadFileAsync(new Uri(NEW_VERSION), @Application.StartupPath + "\\" + "NEW.exe");
DownloadString.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadString_DownloadCompleted);
}
else
{
WindowState = FormWindowState.Normal;
}
}
}
private void DownloadString_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
var result = MessageBox.Show(UPDATE_READY, "", MessageBoxButtons.OKCancel);
if(result == System.Windows.Forms.DialogResult.OK)
{
Process.Start(@Application.StartupPath + "\\" + "Updater.exe");
Application.Exit();
}
else
{
Application.Exit();
}
}
In Load Form1 oder halt in der Load Funktion deiner Form
aufrufen.
Danach lasse ich eine Updater.exe starten die den rest regelt wie Names Change und Programm neu Starten.
Code:
namespace Updater
{
class Program
{
static void Main(string[] args)
{
if(File.Exists("ProgrammName.exe"))
{
File.Delete("ProgrammName.exe");
File.Move("NEW.exe", "ProgrammName.exe");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Process.Start("ProgrammName.exe");
}
else
{
File.Move("NEW.exe", "ProgrammName.exe");
}
}
}
}
Sollte jemand Fragen zum Skript haben meldet euch einfach bei mir.
Personen die C# Lernen möchten sind auch gerne gesehen .