Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update program version 1

Status
Not open for further replies.

SpiritOfLennon

IS-IT--Management
Oct 2, 2001
250
0
0
GB
Hi,
I'm trying to write code that performs the following function.
1) Checks the version of a program on a server. ( I'm doing this by recording the info in a file )
2) Checks the version of the program being run
3) Compares the two and informs the user if they are running an old version
4) Updates the version of the program they are running

I have managed to write the code except that when running the executeable it obviously doesn't like writing over the program it is currently running. Is it possible to exit the program and kick of the batch file after?
Here is the section of code so far.

'Program to copy new version of program over old version
' Open the "Version" file to get the current version
Open "d:\VB\ejmti\version" For Input As #1
Line Input #1, VersionNumber
Close #1

' Get the current version of the program
VersionNumberUser = App.Major & "." & App.Minor & "." & App.Revision
' Create the copy string in order to update
VersionPath = "copy Y:\ejmti\EJMTI.exe " & App.Path & "\" & App.EXEName & ".exe"

' Test the version number
If VersionNumber <> VersionNumberUser Then

' Inform the user
MsgBox &quot;You are running version &quot; & VersionNumberUser & &quot; There is a new version available&quot;

' Create the batch file for copying the new version
Open &quot;d:\VB\ejmti\version.bat&quot; For Output As #2
Print #2, VersionPath
Close #2

MsgBox &quot;New version &quot; & VersionNumber & &quot; has been copied. Exiting. Please restart&quot;

Exit Sub

End If


SOL
I'm only guessing but my guess work generally works for me.
 
Nobody gonna take up the challenge on this one then?

SOL
I'm only guessing but my guess work generally works for me.
 
There's a couple of older threads on this subject that are fairly recent. Search 'em out and see where they went with it.

But, yes it is possible to write a batch file, shell to your batch file, have the main program close, batch file copy over new version of EXE, batch file then restarts the program and then erases itself.

Robert
 
I would just write a second little app that takes command line parameters of the copyfrom and copyto file names. Start it up from the ToBeReplaced application. The ToBeReplaced application shuts down and the CopierApp does the copy and starts the new copy back up. The CopierApp can attempt to open for output the ToBeReplaced app in an adequately error handled loop until the ToBeReplaced app is completely shut down. This would be necessary, because when the CopierApp is activated, technically, the ToBeReplaced app is still running for a few moments. Depending on the speed of your machine and scheduling issues the time it takes to spawn the CopierApp and shut down the ToBeReplaced app will likely cause the CopierApp to fail immediately every time unless it has the smarts to wait around a while for its invoking app to die.

Then do the copy and start it back up again.

 
Thanks for that, I did try searching but couldn't find any threads. Does anyone know what the threads were called?

SOL
I'm only guessing but my guess work generally works for me.
 
Here's one of the threads:

thread222-491354 course, updateing becomes more of a problem if you also need to update or add DLL's or OCX's. It really depends on what you need to do.

Robert
 
As long as you haven't got any ocxs or dlls to register you could code something like this:
- rename the exe who is executing right now
(this works in contrast to delete or copy it...)
- copy the new exe
- eventually start the new exe
- stop the old exe
It's just a suggestion... never coded it for real applications but here my trial-code... perhaps it helps
Code:
Private Sub UpdateVersion(ByVal strpOldPath As String, ByVal strpNewPath As String, blnpRestart As Boolean)
    Const cOld = &quot;old.exe&quot;
    Const cExe = &quot;.exe&quot;
    
    If Right(strpOldPath, 1) <> &quot;\&quot; Then
        strpOldPath = strpOldPath & &quot;\&quot;
    End If
    If Right(strpNewPath, 1) <> &quot;\&quot; Then
        strpNewPath = strpNewPath & &quot;\&quot;
    End If
Code:
    ' erase existing old Version
Code:
    If Dir(strpOldPath & cOld) <> &quot;&quot; Then
        Kill strpOldPath & cOld
    End If
Code:
    ' Rename actual version
Code:
    Name strpOldPath & App.EXEName & cExe As strpOldPath & cOld
Code:
    ' copy new version
Code:
    FileCopy strpNewPath & App.EXEName & cExe, strpOldPath & App.EXEName & cExe
Code:
    ' restart if you wish
Code:
    If blnpRestart = True Then
        Shell strpNewPath & App.EXEName & cExe
    End If
Code:
    ' End the application (should be unload to clean up any garbage...)
Code:
    End
End Sub

Andreas
 
A shiny purple star to our winner, a blown out blackhole to our valiant losers. Thanks Andreas you are the man.

SOL
I'm only guessing but my guess work generally works for me.
 
For anyone that wants to see a copy here it is. It uses a config test file to read in the version number, the server and client path to the executeable. The only issues are that it needs the location of this config file hard coding, which I would prefer not to do or at the very least I would like to do something like
open \\server\directory\file for input
Is there a way to do this?
If anyone can see any other improvements then please let me know.
Okay here's the full code. I'm not using Andrea's idea for testing whether to run the new version but it is still valid.

Private Sub UpdateVersion()

' Program to copy new version of program over old version
' Open the &quot;Version.txt&quot; file to get the current version
Open &quot;Y:\VB\ejmti\version.txt&quot; For Input As #1
'' Open &quot;D:\version.txt&quot; For Input As #1
Input #1, VersionNumber, ExeClientPath, ExeSvrPath
Close #1

' Get the current version of the program
VersionNumberUser = App.Major & &quot;.&quot; & App.Minor & &quot;.&quot; & App.Revision

' Test the version number
If VersionNumber <> VersionNumberUser Then
' Inform the user
MsgBox &quot;You are running version &quot; & VersionNumberUser & &quot; There is a new version available&quot;
MsgBox &quot;New version &quot; & VersionNumber & &quot; has been copied. Exiting. Please restart&quot;
End If

cOld = &quot;old.exe&quot;
cExe = &quot;.exe&quot;
If Right(ExeSvrPath, 1) <> &quot;\&quot; Then
ExeSvrPath = ExeSvrPath & &quot;\&quot;
End If

If Right(ExeClientPath, 1) <> &quot;\&quot; Then
ExeClientPath = ExeClientPath & &quot;\&quot;
End If

' erase existing old Version
If Dir(ExeClientPath & cOld) <> &quot;&quot; Then
Kill ExeClientPath & cOld
End If
' Rename actual version
Name ExeClientPath & App.EXEName & cExe As ExeClientPath & cOld
' copy new version
FileCopy ExeSvrPath & App.EXEName & cExe, ExeClientPath & App.EXEName & cExe
' restart if you wish
Shell ExeClientPath & App.EXEName & cExe
' End the application (should be unload to clean up any garbage...)
End
End Sub


SOL
I'm only guessing but my guess work generally works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top