|
-
Sep 14th, 2007, 07:52 AM
#1
[RESOLVED] [2005] Download new .EXE and switch to new version
We've got this pocket PC app - but this is a general .Net question...
This app will detect that a new version of the .EXE is available - and actually download it through the SQL CLIENT connection from the network server database. We are already storing images in the network server database - so I'm pretty sure I can store a .EXE as well.
I was thinking that I would "write" the new .EXE to the same folder as the current .EXE - but with a different name.
Now the question - how do I chain out to a .BAT file, for instance - that will rename the old .EXE and also rename the new app to take it's place?? I'm pretty sure that the rename operation cannot occur while the app is running (I've seen this fact on regular workstation installs of .EXE's - they are locked while they are running).
So I need to get into a .BAT file (or a little "rename .exe") and have the app itself close - so the rename operations can occur.
-
Sep 14th, 2007, 08:05 AM
#2
Re: [2005] Download new .EXE and switch to new version
What I do is create a second app (called appUpdater) When the application starts I call a check to see if a newer version is stored on a known location (based on date/time of the files). If the running apps date/time is the same or greater then the version stored in the update dir then app continues to load. If the update location has a newer version of the app then the app calls appUpdater and exits. The appUpdater copies the new file (doing an overwrite) then calls the actuall app to start again and exits itself.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 14th, 2007, 08:12 AM
#3
Re: [2005] Download new .EXE and switch to new version
Here's how we did this (although it was for a desktop app, not a mobile, but I think the principle is the same.)
We have an AppLauncher application that gets run first, basically a bootstrapper. It checks for a new version, installs it, then essentially shells out to the actual app itself. This ensures the app isn't in use when we try to overwrite it. The applauncher should never need to be updated since all it is is a shell.
-tg
-
Sep 14th, 2007, 08:18 AM
#4
Re: [2005] Download new .EXE and switch to new version
ok - ok...
Now the million dollar question - what is the .Net code for doing this shell or app call type stuff??
-
Sep 14th, 2007, 08:19 AM
#5
Re: [2005] Download new .EXE and switch to new version
Process.Start(Filenamewithpath) MSDN
Please mark you thread resolved using the Thread Tools as shown
-
Sep 14th, 2007, 08:21 AM
#6
Re: [2005] Download new .EXE and switch to new version
 Originally Posted by danasegarane
Process.Start(Filenamewithpath)
And I can exit the app itself immediately...
...does the Process.Start start the new app immediately?
-
Sep 14th, 2007, 08:22 AM
#7
Re: [2005] Download new .EXE and switch to new version
Here is what I use to check:
vb.net Code:
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
'We Need to generate the Config File if not present
'Config will hold the database type, Database Location, Database Name and the UpdateDirectory
Try
If Not FileIO.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Config.ini") Then
frmConfig.ShowDialog()
End If
If Not FileIO.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Config.ini") Then
MessageBox.Show("You must configure your database and update path to use this application.", "Database Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
e.Cancel = True
End If
'OK we have a Config file now we test newer stuff
'f1 stuff is the Report DLL
'f2 struff is the application
'f3 struff is the config file
Dim objIniFile As clsIniFile
objIniFile = New clsIniFile(My.Application.Info.DirectoryPath & "\Config.ini")
Dim strTName As String = objIniFile.GetString("Configuration", "UpdatePath", "")
Dim strUpdatePath As String = strTName & "\"
Dim strLocalPath As String = My.Application.Info.DirectoryPath & "\"
Dim f1Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "RSMReports.dll")
Dim f2Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "RSM.exe")
Dim f3Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "config.ini")
Dim f1Local As Date = IO.File.GetLastWriteTime(strLocalPath & "RSMReports.dll")
Dim f2Local As Date = IO.File.GetLastWriteTime(strLocalPath & "RSM.exe")
Dim f3Local As Date = IO.File.GetLastWriteTime(strLocalPath & "config.ini")
If f1Local < f1Update Then
IO.File.Copy(strUpdatePath & "RSMReports.dll", strLocalPath & "RSMReports.dll", True)
End If
If f3Local < f3Update Then
IO.File.Copy(strUpdatePath & "config.ini", strLocalPath & "config.ini", True)
End If
If f2Local < f2Update Then
Process.Start(strLocalPath & "RSMUpdater.exe")
e.Cancel = True
End If
Catch ex As Exception
End Try
End Sub
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 14th, 2007, 08:22 AM
#8
Re: [2005] Download new .EXE and switch to new version
Yes it will start the application Immediately
Please mark you thread resolved using the Thread Tools as shown
-
Sep 14th, 2007, 08:31 AM
#9
Re: [2005] Download new .EXE and switch to new version
Here's the rub...
I really have to get the .EXE from the database - as PPC's don't talk to the network very well...
So the main app itself is the one that does the authentication and gets the SQL Client connection to the network database server.
So being that the "discovery" of the new .exe is done by the .exe itself - I'll have that do the download.
And I guess I'll fool with the Process.Start and startup a .BAT file - I can have the .BAT file be created by the old app .exe itself prior to doing the Process.Start.
I just have to work in a pause of some kind to insure that the old app .exe is closed...
-
Sep 14th, 2007, 08:34 AM
#10
Re: [2005] Download new .EXE and switch to new version
I don’t think there is need to write a separate application for update. If you are using .Net Setup than all you need is to add a Class library project and add to it an installer class. In the installer class you add BeforeInstall and AfterInstall events. In the BeforInstall event you write code that will detect if the app is running (you can use Process class for this), if it does than simply call the main form close method of the process. In the AfterInstall event you put the code that will lunch the app. Finally, in the Setup project of the app, under custom actions you add the primary output of the class library under Install folder.
-
Sep 14th, 2007, 08:36 AM
#11
Re: [2005] Download new .EXE and switch to new version
@VBDT - that seems interesting - I'll look into it...
Do you think it will work with the PPC and the fact that the new .EXE is in a database?
-
Sep 14th, 2007, 08:42 AM
#12
Re: [2005] Download new .EXE and switch to new version
VBDT - Ok.... I get it.... but how does the install get launched then? :blink: OOoooohh.... I get it. I think... the app looks to see if there's a new install available, and if so, launches it, which will then close the main app... install, then re-launch the app... if I read that right. I'm not sure I get how the app gets shut down in the first place.
-tg
-
Sep 14th, 2007, 08:47 AM
#13
Re: [2005] Download new .EXE and switch to new version
Are we talking about the actual INSTALL running again?
I don't need that - just a copy in of a new .EXE...
-
Sep 14th, 2007, 08:54 AM
#14
Re: [2005] Download new .EXE and switch to new version
szlamany - I think in your case... what you are looking to do will have to do... since it's the main app that gets the login info, which is needed to grab the exe from the database, copy it to new name then shell to something that renames it and launches it.
It's simple to do, and not all that complicated.
There's one other option, but it's a little more involved. For something this simple, I don't know if it would be worth the effort.
-tg
-
Sep 14th, 2007, 08:55 AM
#15
Re: [2005] Download new .EXE and switch to new version
I think it should work. I think it doesn’t matter where the setup is unless it can be run from that location. At list you can copy the setup to the computer and run it.
-
Sep 14th, 2007, 08:59 AM
#16
Re: [2005] Download new .EXE and switch to new version
 Originally Posted by techgnome
VBDT - Ok.... I get it.... but how does the install get launched then? :blink: OOoooohh.... I get it. I think... the app looks to see if there's a new install available, and if so, launches it, which will then close the main app... install, then re-launch the app... if I read that right. I'm not sure I get how the app gets shut down in the first place.
-tg
Yes that is correct. The application checks to see if there is a new version, if there is than it lunches the setup. The setup its turn shuts down the app if it is running and installs the new app. After all it lunches the app.
-
Sep 14th, 2007, 10:27 AM
#17
Re: [2005] Download new .EXE and switch to new version
I still don't get how the installer shuts down the app...
-tg
-
Sep 14th, 2007, 01:56 PM
#18
Re: [2005] Download new .EXE and switch to new version
This code goes in to the installer class as I explained in my previous post.
vb Code:
Imports System.ComponentModel
Imports System.Configuration.Install
Public Class Installer1
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add initialization code after the call to InitializeComponent
End Sub
Private Sub Installer1_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.AfterInstall
Dim p As New Process
p.StartInfo.FileName = "C:\Program Files\Default Company Name\Setup2\DeviceApplication1.exe"
p.Start()
End Sub
Private Sub Installer1_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeInstall
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle = "Form1" Then
p.CloseMainWindow()
End If
Next
End Sub
End Class
-
Sep 14th, 2007, 02:50 PM
#19
Re: [2005] Download new .EXE and switch to new version
Looping through the processes... I figured... and you';d need to knwo the caption... if there is one... seems like there should be a more elegant way going about doing this../...
-tg
-
Sep 14th, 2007, 04:25 PM
#20
Re: [2005] Download new .EXE and switch to new version
Ok - I dropped the idea for a .BAT file and I'm instead using a little update program written in .net.
This is still in prototype - but it's working and should easliy be moved into production from here.
I'm actually storing the UPDATE program in the database as well - it gets downloaded first then the application gets downloaded and then we Process.Start to the UPDATE program to finish the job.
Code:
Imports System.IO
Module APCUpd
Sub Main(ByVal args As String())
Dim s1 As String = args(0).Replace("~", " ")
MsgBox(s1)
File.Move(Path.Combine(s1, "APC1.txt"), Path.Combine(s1, "APC2.txt"))
End Sub
End Module
This is actually stored in a database on a network server and "dropped" onto a pocket PC with this code
Code:
Dim ExeData As Byte() = DirectCast(LDrc.ExecuteScalar, Byte())
Dim fs As New FileStream(Path.Combine(strBaseFolder, "APCUpd.exe"), FileMode.CreateNew)
Using bw As BinaryWriter = New BinaryWriter(fs)
bw.Write(ExeData)
bw.Close()
End Using
And then it's run with this:
Code:
Process.Start(Path.Combine(strBaseFolder, "APCUpd.exe"), strBaseFolder.Replace(" ", "~"))
The reason for the tilde replace is that spaces were causing multiple "arguments" to be passed into the SUB MAIN()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|