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