-
May 23rd, 2015, 04:17 AM
#1
Thread Starter
Lively Member
[RESOLVED] Auto Updater Error
Hi All,
I'm trying to add auto updater to my project. My idea is something like this: While executing, the first thing that the exe checks is, is there any update available in Drop Box. If there is any, it has to replace with the new update. When i'm checking through IDE, it works fine. But after creating exe and checking via exe, it's showing error 75 - Path/File Access Error. I don't know Why this is happening.. Here my code:
Code:
If Not IsIDE Then
'=========== checks for an updated exe shared on dropbox ====
APPDIR = DropBoxFolder ' gets the Drop Box folder Path in the system
APPDIR = APPDIR & "\CO\Releases"
APPEXE = APPDIR & "\MyApp.exe"
APPVER = APPDIR & "\version.txt"
APPREP = APPDIR & "\Reports"
Open APPVER For Input As #1
Input #1, MyVer
Close #1
If FileCheck.FileExists(APPEXE) Then
APPFullName = App.Path & "\" & App.Title & ".exe"
If Trim(MyVer) <> gKey.getKeyString("APP_VERSION") Then
Call CopyNewEXE
End If
End If
End If
Private Sub CopyNewEXE()
Dim FileCopy As New Scripting.FileSystemObject
Dim Copy As String, AppReport As String
On Error GoTo ErrHandler
If FileCopy.FileExists(APPEXE) = True Then
AppReport = App.Path & "\Reports"
If FileCopy.FolderExists(APPREP) Then
If FileCopy.FolderExists(AppReport) Then FileCopy.DeleteFolder AppReport
FileCopy.CopyFolder APPREP, AppReport, True
End If
APPFullName = App.Path & "\" & App.Title & ".exe"
Kill APPFullName
Copy = App.Path & "\"
If FileCopy.FileExists(APPEXE) = True Then
FileCopy.CopyFile APPEXE, Copy
End If
If FileCopy.FileExists(APPFullName) = True Then
If MyVer > gKey.getKeyString("APP_VERSION") Then
gKey.setKeyString "APP_VERSION", MyVer
End If
End If
ShowMsgBox "Exe Updated", "OK"
End If
Exit Sub
ErrHandler:
ShowMsgBox ErrMsg & Err.Number & "-" & Err.Description, "OK"
End Sub
Last edited by nasar; May 23rd, 2015 at 10:05 PM.
-
May 23rd, 2015, 04:40 AM
#2
Re: Auto Updater Error
as you may already know, this means the file is either being used \ does not exist \ user does not have permission to access the file.
which line highlights when the error occurs ?
how are you 'downloading' your up-to-date file ?
you posted only the "isIDE = False" part , we have no way to compare between in-ide and out of it.
To isolate the problem, i would remove all the relevant 'On Error' tags and define temporary constant paths instead of App.Path just to let the ide throw an error.
-
May 23rd, 2015, 04:48 AM
#3
Thread Starter
Lively Member
Re: Auto Updater Error
Error is with the line Kill APPFullName.
It copies the updated file from Drop Box folder and replaces the old one. I'm using FileSystemObject for this purpose.
-
May 23rd, 2015, 04:51 AM
#4
Re: Auto Updater Error
Good. and i assume AppFullName points to the EXE that is currently running ?
-
May 23rd, 2015, 04:52 AM
#5
Thread Starter
Lively Member
-
May 23rd, 2015, 04:55 AM
#6
Re: Auto Updater Error
If i'm holding a piece of paper, and you want to throw that piece of paper, you would first need to take that piece of paper off me for you to throw it.
Windows stops you from cutting the branch on which you're sitting.
-
May 23rd, 2015, 05:02 AM
#7
Thread Starter
Lively Member
Re: Auto Updater Error
that's true. But in that case how could this works fine in IDE without any errors. It works correctly ; the Reports folder is copied along with the exe and the version is updated in the database.
-
May 23rd, 2015, 05:04 AM
#8
Re: Auto Updater Error
yes that is because in the IDE, the IDE process (vb6.exe) is the branch you're sitting on.
try to kill it see what happens. (bk it up first ofcourse)
What you're trying to do is usually handled by two different .exe files.
Last edited by stum; May 23rd, 2015 at 05:07 AM.
-
May 23rd, 2015, 05:06 AM
#9
Thread Starter
Lively Member
Re: Auto Updater Error
Is there any other way to do this?
the error occurs when i'm trying to kill the one i'm executing
And, these two files are different files in two different locations
Last edited by nasar; May 23rd, 2015 at 05:11 AM.
-
May 23rd, 2015, 05:09 AM
#10
Re: Auto Updater Error
Originally Posted by nasar
Is there any other way to do this?
yes. two different EXEs.
One loads, the other shuts down, replaces what needs to be replaced, loads the replaced exe, and shuts itself down .
-
May 23rd, 2015, 02:36 PM
#11
Re: Auto Updater Error
This example shows how a single EXE can replace a currently running instance of itself with a new version (for simplicity, this demo just copies the old EXE). It relies on the fact that executables can be renamed even while they're running. This example also shows how the old version can instruct the new version to delete the old executable file after it terminates. Compile the following code first before trying it:
Code:
Option Explicit 'In a standard module
Private Const DELETE_THIS As String = " /DeleteThis "
Private Declare Sub Sleep Lib "kernel32.dll" (Optional ByVal dwMilliseconds As Long)
Private Sub Main()
Dim sExeFileName As String, sTmpFileName As String
If ProcessCmdLineArgs(" " & Command$ & " ") Then Exit Sub
sExeFileName = App.Path & "\" & App.EXEName & ".exe"
sTmpFileName = App.Path & "\" & App.EXEName & ".tmp"
'If sTmpFileName exists, delete it
On Error Resume Next
Select Case (GetAttr(sTmpFileName) And vbDirectory) <> vbDirectory
Case True: SetAttr sTmpFileName, vbNormal: Kill sTmpFileName
End Select
On Error GoTo 0
'Rename this EXE
MsgBox "Before renaming...", vbInformation
Name sExeFileName As sTmpFileName
'Replace old EXE with new EXE
MsgBox "Before copying...", vbInformation
FileCopy sTmpFileName, sExeFileName
'Tell new EXE to delete old EXE
MsgBox "Before starting new EXE & deleting old EXE...", vbInformation
Shell sExeFileName & DELETE_THIS & """" & sTmpFileName & """", vbNormalFocus
End Sub
Private Function ProcessCmdLineArgs(ByRef sCmdLine As String) As Boolean
Dim nTries As Integer, StartPos As Long, EndPos As Long, sFileName As String
StartPos = InStr(1&, sCmdLine, DELETE_THIS, vbTextCompare)
If StartPos Then
StartPos = InStr(StartPos + Len(DELETE_THIS), sCmdLine, """")
EndPos = InStr(StartPos + 1&, sCmdLine, """")
If EndPos Then
sFileName = Mid$(sCmdLine, StartPos + 1&, EndPos - StartPos - 1&)
If LenB(sFileName) Then
On Error Resume Next
SetAttr sFileName, vbNormal
For nTries = 1 To 10
Err.Clear
Kill sFileName
If Err Then Sleep 500&: DoEvents Else Exit For
Next
ProcessCmdLineArgs = MsgBox("End demo?", vbQuestion Or vbYesNo) = vbYes
End If
End If
End If
End Function
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
May 24th, 2015, 04:07 AM
#12
Thread Starter
Lively Member
Re: Auto Updater Error
@stum, I tried ur method and it worked!!! Thanks alot dear....
@Bonnie West , wanna try ur method too..
-
May 24th, 2015, 10:15 PM
#13
Thread Starter
Lively Member
Re: Auto Updater Error
Bonnie West, Thank you so much... Your code worked fine dear..
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
|