Solved

Create an upgrade routine

Posted on 2008-10-31
2
314 Views
Last Modified: 2013-11-27
Hello,

I need to create a routine to upgrade my application.
When the user run the application it checks on the db if the actual version is the latest one. If it doesn't than a message box ask to the user: "A newer version is available. Do you want to install it?".
If the user confirm a .BAT file is run that deletes the .exe and copies from the server the actual version.

Tha problem is that the .bat can't delete the file because it is running (The process cannot access the file because it is being used by another process.). I need to "say" to my application to close himself and run the .BAT but I don't know how.

Any idea?

Thanks
Inside Main routine:
 

    If goApp.Version > goUtl.TranslateVer(sAppVersion) Then

        If MsgBox("A newer version is available. & vbCr & _

                    "Do you want to install it now?", vbYesNo Or vbInformation, "New Version available") = vbYes Then

            ' User selected Yes

            If InstallLastVersion = True Then

                MsgBox "Installation completed." & vbCr & "Please restart the application.", vbInformation, "Installation complete"

            Else

                MsgBox "Errore during installation." & vbCr & "Please contact your administrator.", vbCritical, "Error"

            End If

        End If
 

----------------------------------------
 

Public Function InstallLastVersion() As Boolean
 

Dim shell

On Error GoTo ErrorHandler
 

    Set shell = CreateObject("wscript.shell")

    shell.run App.path & "\UpgradeXps.bat"

    InstallLastVersion = True
 

ErrorCleanUp:

   On Error Resume Next

   ' cleaning variables

    Set shell = Nothing

   On Error GoTo 0

   Exit Function

ErrorHandler:

    InstallLastVersion = False

    Resume ErrorCleanUp

End Function
 

--------------------------
 

UpgradeXPS.bat file:
 

ECHO OFF

DEL /q d:\std\xps.exe

d:

CD \STD\XPS

copy \\servername\std\XPS.exe 
 

-----------------------------

Open in new window

0
Comment
Question by:webluca
2 Comments
 
LVL 11

Accepted Solution

by:
Antagony1960 earned 500 total points
ID: 22850283
It's not very elegant but you can close the application by ending it's process, if you know its name:

Public Function EndProcess(sProcessName As String) As Boolean
Dim winProcess
    For Each winProcess In GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Process")
        If LCase(winProcess.Name) = LCase(sProcessName) Then
            winProcess.Terminate
            EndProcess = True
            Exit For
        End If
    Next
End Function

Note: This will only work from an executable or script, not from the VB IDE.
0
 

Author Closing Comment

by:webluca
ID: 31512030
Thanks for the idea.
I Modified the .bat file adding TASKKILL /F /IM "application_name.exe"
before deleting the application.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now