Avatar billede jesper2003 Nybegynder
22. juli 2006 - 16:14 Der er 2 kommentarer og
1 løsning

AutoUpdate problem i vb.net

Hej er ved at lave en AutoUpdate til mit program men kan ikke komme vidre.. min kode er sådan

AutoUpdate.vb

Public Class AutoUpdate
    Public Function AutoUpdate(ByRef CommandLine As String) As Boolean
        Dim Key As String = "&**#@!" ' any unique sequence of characters
        ' the file with the update information
        Dim sfile As String = "update.dat"
        ' the Assembly name
        Dim AssemblyName As String = _
                System.Reflection.Assembly.GetEntryAssembly.GetName.Name
        ' here you need to change the web address
        Dim RemotePath As String = _
            "http://c4.guf4you.dk/"
        ' where are the files for a specific system
        Dim RemoteUri As String = RemotePath & AssemblyName & "/"

        ' clean up the command line getting rid of the key
        CommandLine = Replace(Microsoft.VisualBasic.Command(), Key, "")
        ' Verify if was called by the autoupdate
        If InStr(Microsoft.VisualBasic.Command(), Key) > 0 Then
            Try
                ' try to delete the AutoUpdate program,
                ' since it is not needed anymore
                System.IO.File.Delete(Application.StartupPath & "\autoupdate.exe")
            Catch ex As Exception
            End Try
            ' return false means that no update is needed
            Return False
        Else
            ' was called by the user
            Dim ret As Boolean = False ' Default - no update needed
            Try
                Dim myWebClient As New System.Net.WebClient 'the webclient
                ' Download the update info file to the memory,
                ' read and close the stream
                Dim file As New System.IO.StreamReader( _
                    myWebClient.OpenRead(RemoteUri & sfile))
                Dim Contents As String = file.ReadToEnd()
                file.Close()
                ' if something was read
                If Contents <> "" Then
                    ' Break the contents
                    Dim x() As String = Split(Contents, "|")
                    ' the first parameter is the version. if it's
                    ' greater then the current version starts the
                    ' update process
                    If x(0) > Application.ProductVersion Then
                        ' assembly the parameter to be passed to the auto
                        ' update program
                        ' x(1) is the files that need to be
                        ' updated separated by "?"
                        Dim arg As String = Application.ExecutablePath & "|" & _
                                    RemoteUri & "|" & x(1) & "|" & Key & "|" & _
                                    Microsoft.VisualBasic.Command()
                        ' Download the auto update program to the application
                        ' path, so you always have the last version runing
                        myWebClient.DownloadFile(RemotePath & "autoupdate.exe", _
                            Application.StartupPath & "\autoupdate.exe")
                        ' Call the auto update program with all the parameters
                        System.Diagnostics.Process.Start( _
                            Application.StartupPath & "\autoupdate.exe", arg)
                        ' return true - auto update in progress
                        ret = True
                    End If
                End If
            Catch ex As Exception
                ' if there is an error return true,
                ' what means that the application
                ' should be closed
                ret = True
                ' something went wrong...
                MsgBox("There was a problem runing the Auto Update." & vbCr & _
                    "Please Contact [contact info]" & vbCr & ex.Message, _
                    MsgBoxStyle.Critical)
            End Try
            Return ret
        End If
    End Function

    Private Sub AutoUpdate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Og main.vb

Imports System.IO
Imports System.Net
Module Main

    Public Sub Main()
        Dim ExeFile As String ' the program that called the auto update
        Dim RemoteUri As String ' the web location of the files
        Dim Files() As String ' the list of files to be updated
        Dim Key As String ' the key used by the program when called back
        ' to know that the program was launched by the
        ' Auto Update program
        Dim CommandLine As String ' the command line passed to the original
        ' program if is the case
        Dim myWebClient As New WebClient ' the web client
        Try
            ' Get the parameters sent by the application
            Dim param() As String = Split(Microsoft.VisualBasic.Command(), "|")
            ExeFile = param(0)
            RemoteUri = param(1)
            ' the files to be updated should be separeted by "?"
            Files = Split(param(2), "?")
            Key = param(3)
            CommandLine = param(4)
        Catch ex As Exception
            ' if the parameters wasn't right just terminate the program
            ' this will happen if the program wasn't called by the system
            ' to be updated
            Exit Sub
        End Try
        Try
            ' Process each file
            For i As Integer = 0 To Files.Length - 1
                Try
                    ' try to rename the current file before download the new one
                    ' this is a good procedure since the file can be in use
                    File.Move(Application.StartupPath & "\" & Files(i), _
                        Application.StartupPath & "\" & _
                        Now.TimeOfDay.TotalMilliseconds & ".old")
                Catch ex As Exception
                End Try
                ' download the new version
                myWebClient.DownloadFile(RemoteUri & Files(i), _
                    Application.StartupPath & "\" & Files(i))
            Next
            ' Call back the system with the original command line
            ' with the key at the end
            System.Diagnostics.Process.Start(ExeFile, CommandLine & Key)
            ' do some clean up -  delete all .old files (if possible)
            ' in the current directory
            ' if some file stays it will be cleaned next time
            Dim S As String = Dir(Application.StartupPath & "\*.old")
            Do While S <> ""
                Try
                    File.Delete(Application.StartupPath & "\" & S)
                Catch ex As Exception
                End Try
                S = Dir()
            Loop
        Catch ex As Exception
            ' something went wrong...
            MsgBox("There was a problem runing the Auto Update." & vbCr & _
                "Please Contact [contact info]" & vbCr & ex.Message, _
                MsgBoxStyle.Critical)
        End Try
    End Sub
End Module



Jeg kan ikke finde ud af hvordan jeg skal få den til at finde den nyeste version.

Og ved ikke helt hvad autoupdate.exe skal bruges til og hvad dette betyder

The auto update web folder

The auto update web folder should have a folder for each system you want to upgrade. The root folder is the one that you will refer on the RemotePath variable. The AutoUpdate.exe program should be on this folder. Each subfolder should be named as the assembly name (normally the program name without the extension). Inside the program folder you save the files that you want to update and the file update.dat with the last file version and the files that you want to update. The first parameter is the version and the second parameter separated by a "|" are the files that you want to update, which are separated by "?" as follows:

1.2.1234.5543|MyProgram.exe?file1.txt?file2.cfg

Det er her fra jeg har fundet det hele
http://www.codeproject.com/vb/net/autoupdate.asp
Avatar billede mrbonus Novice
25. juli 2006 - 13:33 #1
Jeg har valgt at lave mig en WebService, som jeg så spørger om der er kommet en ny version, hvorefter man kan hente filen som bytes fra webservicen.
VersionsStyring klarer jeg ved at ligge en xml fil som webservicen har fat i. kunne se således ud.

<?xml version="1.0" encoding="utf-16"?>
<DOCUMENT>
    <UPDATEINFO>
        <CURRENTVERSION>1.0.0.0</CURRENTVERSION>
        <SETUPFILENAME>MyProgramSetup.msi</SETUPFILENAME>
    </UPDATEINFO>
</DOCUMENT>

Hvis man så sender programmets version med over, så kan webservicen se om der er kommet en nyere version, som den så kan hente, og opdatere dit program med

Du skrev
"Og ved ikke helt hvad autoupdate.exe skal bruges til og hvad dette betyder"
Den skal bruges til at opdatere dit program med, hvis du har lavet nye opdateringer.
Avatar billede jesper2003 Nybegynder
05. august 2006 - 16:00 #2
Okay nu har jeg lagt denne op
http://c4.guf4you.dk/program/update/update.xml

Men hvordan får jeg det til at virke i programmet?

Synes jeg har prøvet forskellige ting uden held
Avatar billede jesper2003 Nybegynder
01. september 2006 - 21:37 #3
lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester