Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[TuT] [VB .Net | C#] Simple Updating System

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());
interesting and how to check if update avaible?
lohol thats not familiar to other programs , delete and start a new one
(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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by CacheIsAFagOct 17, 2017 05:15 AM 20 1,190 Oct 17, 2017 05:15 AM
Last Post: CacheIsAFag
[.NET] by GruntStylDec 6, 2016 04:45 AM 1 175 Dec 6, 2016 04:45 AM
Last Post: Rhez
[.NET] by Debit.Oct 22, 2016 12:06 PM 6 190 Oct 22, 2016 12:06 PM
Last Post: Debit.