Solved

VB6 Run-time error '5' when calling shell

Posted on 2014-02-14
14
968 Views
Last Modified: 2014-02-17
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?
0
Comment
Question by:mossmis
  • 4
  • 2
  • 2
  • +2
14 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859646
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?
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39859714
Does your App.Path contain spaces?

--
Chris
0
 

Author Comment

by:mossmis
ID: 39859840
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.
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859847
Can you post the code (at least the full subroutine which has the offending line in it)?
0
 

Author Comment

by:mossmis
ID: 39859923
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

End Sub

Open in new window

0
 
LVL 45

Expert Comment

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

Open in new window

0
 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 39862167
@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
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39862770

@aikmark
  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.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39863303
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.
0
 

Author Comment

by:mossmis
ID: 39864837
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.
0
 

Author Comment

by:mossmis
ID: 39864881
jkaios caught my mistake. Why isn't he getting the points?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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