Hack Forums
[C#] [TuT] [VB .Net | C#] Simple Updating System - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [TuT] [VB .Net | C#] Simple Updating System (/showthread.php?tid=528186)



[TuT] [VB .Net | C#] Simple Updating System - xFic - Jul 8, 2010

Heres some code to make a simple updating system using command line parameters 😉

Create a new project then add the below code to your main forms load event.

VB .Net
Code
If Environment.GetCommandLineArgs.Length > 1 Then
    Dim args As String() = Environment.GetCommandLineArgs()
    Select Case args(1)
    Case "update"
    Dim ps As Process() = Process.GetProcessesByName(args(2))
    For Each p As Process In ps
    p.Kill()
    p.WaitForExit()
    Next
    IO.File.Delete(args(2) & ".exe")
    End Select
  End If

C#
Code
if (Environment.GetCommandLineArgs().Length > 1)
    {
    string[] args = Environment.GetCommandLineArgs();
    switch (args[1])
    {
    case "update":
    System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName(args[2]);
    foreach (System.Diagnostics.Process p in ps)
    {
    p.Kill();
    p.WaitForExit();
    }
    System.IO.File.Delete(args[2] + ".exe");
    break;
    }
    }

WAIT BUT HOW DOES THIS WORK?!...
It's simple, you get your application to download the new exe to the SAME directory your applications currently in.
Then you get your application to start the new exe with the code below.
the new exe will then close and delete the old one.

VB .Net
Code
Process.Start("new.exe", "update " & My.Application.Info.AssemblyName)

C#
Code
Process.Start("new.exe", "update " + this.GetType().Assembly.GetName().Name.ToString());



* - bobinski - Dec 28, 2012

interesting and how to check if update avaible?


* - Tafelpoot - Dec 28, 2012

lohol thats not familiar to other programs , delete and start a new one


* - Dark_Noodles - Dec 28, 2012

(Dec 28, 2012 11:37 AM)bobinski Wrote:  interesting and how to check if update avaible?

Holy shit, thanks for bringing back a two year old thread.