Solved

VB6 Run-time error '5' when calling shell

Posted on 2014-02-14
14
900 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
Comment Utility
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
Comment Utility
Does your App.Path contain spaces?

--
Chris
0
 

Author Comment

by:mossmis
Comment Utility
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
 
LVL 15

Expert Comment

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

Author Comment

by:mossmis
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 45

Expert Comment

by:aikimark
Comment Utility
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
Comment Utility
@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
Comment Utility

@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
Comment Utility
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
Comment Utility
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
Comment Utility
jkaios caught my mistake. Why isn't he getting the points?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now