Solved

Error 70 - Permission Denied

Posted on 2004-08-26
3
550 Views
Last Modified: 2008-01-09
I have an application that checks if there is a new version available. If so, I launch another application (using Shell) to copy the new exe file from a Network drive down to the workstation.

I first terminate the original application from within the second application before i "Delete" the exe file and then copy the the file from the Network (the new exe file) onto the workstation. After copying, I re-launch the first application (using Shell again) and then terminate the second application.

Below is the code that I have and it works only if I have the MsgBox. Without it, it throws an Error 70 - Permission Denied error. I was thinking that without the MsgBox, the thread might not have terminated just yet and that the program is still in memory. That's why the exe file may be locked and thus giving the Permission Denied error. I've tried using Sleep to delay the deletion process to no avail.

Does anybody know the reason why this is happening? I can live with what I have right now but I would like to know how this MsgBox can affect the deletion process.


Thanks a lot!


    Dim fso As New FileSystemObject
    Dim fu As File, fi As File
    Dim a As Integer
    Dim iPath As String

    On Error GoTo Err_Handler
    'get update exe & installed exe
    '
    Set fu = fso.GetFile(g_ini_UNLAB_Update & "\" & PROGRAM_NAME)
    Set fi = fso.GetFile(App.Path & "\" & PROGRAM_NAME)

    'wait 1 second then copy new version of the application
    '
    SetMsg "Please wait... Copying updated version of the Application."
    Sleep 1000
   
    iPath = fi.Path     ': Set fi = Nothing       'save installed path to variable

    'without the msgbox below, this code will throw an error 70 - Permission Denied
    '
    a = MsgBox("Application about to be upgraded! Continue?", vbQuestion + vbYesNo, Me.Caption)
    If a = vbNo Then Shell iPath & " 0", vbNormalFocus: GoTo Terminate
   
    'Kill iPath                              'delete old version
    fi.Delete
    fu.Copy iPath                           'copy new version
   
    SetMsg "Latest version of the application installed."
    Sleep 2000
    SetMsg "Please wait... relaunching latest version of the application."
    Sleep 3000
   
    'launch a new thread of latest application version
    '
    Shell iPath, vbNormalFocus
   
    'destroy file system objects
    '
    Set fso = Nothing: Set fu = Nothing: Set fi = Nothing
   
    'terminate this program
    '
Terminate:
    Unload Me
    Exit Sub
   
Err_Handler:
    MsgBox Err.Number & " - " & Err.Description & " - " & Err.Source
0
Comment
Question by:PePi
3 Comments
 
LVL 11

Expert Comment

by:coopzz
ID: 11909750
you can probably try to execute the same thing a few hundred time check for an error do again
put your doevent and sleep statements so whatever it is has a chance to run the the other process.

hope it works...

   Dim l As Long
    '1000 it will try 1000 times more if you want
    Do Until l >= 1000
        On Error Resume Next
       
        '##NOTE: what ever it is your trying to do.
        DoEvents
        sleep 100  'hopefully smaller
    Loop
   
0
 
LVL 7

Accepted Solution

by:
Smallint earned 500 total points
ID: 11911488

Try to wait until YourOrginal.exe is really terminated.

Cheers


Private Declare Function Process32First Lib "kernel32" _
(ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Private Declare Function Process32Next Lib "kernel32" _
(ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Private Declare Function CreateToolhelp32Snapshot Lib _
"kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
   
Private Type PROCESSENTRY32
           dwSize As Long
           cntUsage As Long
           th32ProcessID As Long
           th32DefaultHeapID As Long
           th32ModuleID As Long
           cntThreads As Long
           th32ParentProcessID As Long
           pcPriClassBase As Long
           dwFlags As Long
           szExeFile As String * 260
End Type

Private Const TH32CS_SNAPPROCESS = &H2&


Public Function IsExeRunning(ByVal ExeFind As String) As Boolean
  Dim hProc As Long, ExeName As String
  Dim lRet As Long, Proc As PROCESSENTRY32
  Dim g As Long, sDeighton As String
  Dim sClean As String
  Dim sAtom As String
 
 
  hProc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
  IsExeRunning = False
                                           
  If hProc = 0 Then
      Exit Function
  End If
                 
   Proc.dwSize = Len(Proc)
   lRet = Process32First(hProc, Proc)
                 
   Do While lRet
     ExeName = Left(Proc.szExeFile, Len(Proc.szExeFile) - 1)
     sClean = ""
     For g = 1 To Len(ExeName)
         sAtom = Mid(ExeName, g, 1)
         If sAtom = Chr(0) Then
                Exit For
         Else
                sClean = sClean & sAtom
         End If
     Next
     sDeighton = ""
     For g = Len(sClean) To 1 Step -1
         If Mid(sClean, g, 1) = "\" Then Exit For
            sDeighton = Mid(sClean, g, 1) & sDeighton
     Next
                                       
     If UCase(sDeighton) = UCase(ExeFind) Then
          IsExeRunning = True
          Exit Function
     End If
                     
      lRet = Process32Next(hProc, Proc)
  Loop
End Function


'------

While IsExeRunning("YourOrginal.exe") = true
     Sleep 1000
Wend


0
 
LVL 6

Author Comment

by:PePi
ID: 11914230

thanks for all the help. SmallInt gets the points.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

20 Experts available now in Live!

Get 1:1 Help Now