-
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!
-
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
-
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