• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Create an upgrade routine


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?

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"
                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
   On Error Resume Next
   ' cleaning variables
    Set shell = Nothing
   On Error GoTo 0
   Exit Function
    InstallLastVersion = False
    Resume ErrorCleanUp
End Function
UpgradeXPS.bat file:
DEL /q d:\std\xps.exe
copy \\servername\std\XPS.exe 

Open in new window

1 Solution
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
            EndProcess = True
            Exit For
        End If
End Function

Note: This will only work from an executable or script, not from the VB IDE.
weblucaAuthor Commented:
Thanks for the idea.
I Modified the .bat file adding TASKKILL /F /IM "application_name.exe"
before deleting the application.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now