Results 1 to 3 of 3

Thread: Overriding itself??

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Overriding itself??

    Hi All,

    Hope you are all having a good day.

    I have an application on a PDA which collects data and basically sends to back to a secure FTP server. My problem is I want to send a new program file, i.e get it to override itself. On the desktop you can do a command prompt command to schedule it just after you close the app. Is there anyway in vb.net cf to do something similar.

    I know I can right a small app to do it but it means getting all the file transfer routine in another project.

    Cheers for any help,

    Jiggy!

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Overriding itself??

    Hi,
    this is quite an old article, but is still valid.
    There is a sample here but I have no experience of it.
    Finally there are several samples here

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Overriding itself??

    We use this method...

    Little program called APCUPD.exe - looks like this

    Code:
    Imports System.IO
    
    Module APCUpd
    
        Sub Main(ByVal args As String())
    
            Dim s1 As String = args(0).Replace("~", " ")
            Dim s2 As String = args(1)
    
            s2 = "Old" & s2
    
            Dim s3 As String = Path.Combine(s1, "APC" & s2 & ".exe")
    
            Try
                File.Delete(s3)
            Catch ex As Exception
                Exit Try
            End Try
    
            Try
                File.Move(Path.Combine(s1, "APC.exe"), s3)
            Catch ex As Exception
                Exit Sub
            End Try
    
            Try
                File.Move(Path.Combine(s1, "APCNew.exe"), Path.Combine(s1, "APC.exe"))
            Catch ex As Exception
                Exit Sub
            End Try
    
        End Sub
    
    End Module
    When then main PPC app detects a new version (stored in a database for us - not via FTP) - it's copied to the PPC with this code. First we copy a fresh version of APCUPD.exe to the PPC and then a new version of the main app - APC.exe (called APCnew.exe when it's created)

    Code:
            If UpdStat Then
                Try
                    LDrc.Connection = LDcn
                    LDrc.CommandType = Data.CommandType.StoredProcedure
                    LDrc.CommandText = "GetStuExes_P"
                    LDrc.Parameters.Add(New SqlParameter("@ExeName", Data.SqlDbType.VarChar, 255, Data.ParameterDirection.Input, False, 0, 0, "", Data.DataRowVersion.Default, "APCUpd"))
    
                    Dim ExeData As Byte() = DirectCast(LDrc.ExecuteScalar, Byte())
    
                    LDrc.Parameters.Clear()
    
                    Dim fs As New FileStream(Path.Combine(strBaseFolder, "APCUpd.exe"), FileMode.Create)
                    Using bw As BinaryWriter = New BinaryWriter(fs)
                        bw.Write(ExeData)
                        bw.Close()
                    End Using
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Error")
                    UpdStat = False
                End Try
            End If
    
            If UpdStat Then
                Try
                    LDrc.Connection = LDcn
                    LDrc.CommandType = Data.CommandType.StoredProcedure
                    LDrc.CommandText = "GetStuExes_P"
                    LDrc.Parameters.Add(New SqlParameter("@ExeName", Data.SqlDbType.VarChar, 255, Data.ParameterDirection.Input, False, 0, 0, "", Data.DataRowVersion.Default, "APC"))
    
                    Dim ExeData As Byte() = DirectCast(LDrc.ExecuteScalar, Byte())
    
                    LDrc.Parameters.Clear()
    
                    LDcn.Close()
    
                    Dim fs As New FileStream(Path.Combine(strBaseFolder, "APCNew.exe"), FileMode.Create)
                    Using bw As BinaryWriter = New BinaryWriter(fs)
                        bw.Write(ExeData)
                        bw.Close()
                    End Using
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Error")
                    UpdStat = False
                End Try
            End If
    and then the APCUPD.exe is started to do the renaming...
    Code:
            If UpdStat Then
                Try
                    booAPCUpd = True
                    Process.Start(Path.Combine(strBaseFolder, "APCUpd.exe"), strBaseFolder.Replace(" ", "~") & " " & appVersion.Replace(".", ""))
                    Me.Close()
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Error")
                    UpdStat = False
                End Try
            End If

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width