?
Solved

Error 70 - Permission Denied

Posted on 2004-08-26
3
Medium Priority
?
569 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

719 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