VB6 Run-time error '5' when calling shell

I get this error from VB6 when calling this line:

Run-time error '5'

GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)

I do not see any setfocus in my code that I usually see through this error. This code does work by the way in a clean project with noting else.

Any suggestions?
Who is Participating?
jkaiosConnect With a Mentor IT DirectorCommented:
@author (mossmis)
  should line 9 in your code reference "updateapp.bat" instead of "errors.txt" ?

  line 6: fso.CreateTextFile "updateapp.bat" does NOT match
  line 20: App.Path & "\updateapp.bat"

============ edited by aikimark
David L. HansenProgrammer AnalystCommented:
What do you mean by:
This code does work by the way in a clean project with noting else.
How is your current setup not clean?
Does your App.Path contain spaces?

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.

mossmisAuthor Commented:
Chris, the app.path does contain spaces. But this works when I isolate the code in a new project with just that command. I'm not sure what else might be causing the error.
David L. HansenProgrammer AnalystCommented:
Can you post the code (at least the full subroutine which has the offending line in it)?
mossmisAuthor Commented:
Public Sub UpdateCurrentApp()
'If the App version doesn't match automatically update the app

Dim fso As New FileSystemObject
    If Not fso.FileExists(App.Path & "\updateapp.bat") Then
        fso.CreateTextFile "updateapp.bat"
    End If

    Open App.Path & "\errors.txt" For Output As #1
    Print #1, "ECHO Please Wait.....Automatically Updating to New Version"
    Print #1, "Timeout 5"
    Print #1, "%~d1"
    Print #1, "cd ""%~p1"""
    Print #1, "copy /y """; UpdateAppFolder; UpdateAppEXE; """"; " "; UpdateAppEXE
    Print #1, "Timeout 1"
    Print #1, "start "; UpdateAppEXE
    Print #1, "exit"
    Close #1
    GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)

End Sub

Open in new window

Quote-delimit the path/filename:
GetApp = Shell(Chr(34) & App.Path & "\updateapp.bat" & Chr(34), vbNormalNoFocus)

Open in new window


  actually, it should be Chr(32), which is the character code for a SPACE and not Chr(34), which is the character code for a double quote (")
No.  You should use a quote delimiter.
jkaiosIT DirectorCommented:
No.  You should use a quote delimiter.

Yes, that's right.  My bad.  I forgot that referencing a directory that has space in it must be enclosed by double quotes.
mossmisAuthor Commented:
Son of a........... line 9 had a bad file name (I copied code from another project of mine). That little thing fixed it. I didn't need to add extra quotes; I took care of it in line 14.

Thanks for catching that mistake.
mossmisAuthor Commented:
jkaios caught my mistake. Why isn't he getting the points?
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.

All Courses

From novice to tech pro — start learning today.