Tech Support Guy banner

VB6 Using Shell Command

47953 Views 11 Replies 7 Participants Last post by  DrewUberAlles
Hi all,

I have the following code attempting to run a batch file (zipper.exe). However each time I run it, a "file not found" error appears, despite the fact that I have double checked the file's path numerous times.

Is there something I am missing here, I thought this would be relatively simple before I started it. :eek:

Private Sub Command1_Click()
Dim path As String
Dim runExe As Double

path = "C:\Program Files\C&F Customer Management\2005_Working_Version\"
runExe = Shell(path & "Zipper.exe", vbMaximizedFocus)

End Sub
Status
Not open for further replies.
1 - 12 of 12 Posts
I apologise if I'm being stupid, but are you sure the file is named zipper.exe and not zipper.bat.
I have tried both file extensions, both .exe and .bat.

The shell command works for me if I am to access any other type of .exe file, however in this instance the file refuses to be opend/run from VB6
Are you sure that filename that you are attempting to execute exists in that particluar folder. Go to the folder "C:\Program Files\C&F Customer Management\2005_Working_Version\" with explorer and make sure that file is there. Then ensure that in your code you are calling the program/file with correct extension .exe or .bat.
Run this code, and report back what error it returns and what number:
Code:
Private Sub Command1_Click()
    Dim path As String
    Dim runExe As Double

    path = "C:\Program Files\C&F Customer Management\2005_Working_Version\"
    runExe = Shell(path & "Zipper.exe", vbMaximizedFocus)

ErrorHandling:
    MsgBox Error.Description & vbCrLf & Error.Number
End Sub
The error message says "Object Required"

Could it be the case that the file I am trying to load cant be accesed in this way? Maybe because its not a proper executable, just a text file with the .exe extension??

The .exe file contains the following commands

Code:
cd \Program files\winzip
wzzip "C:\Program Files\C&F Customer Management\2005_Working_Version\Database.zip" "C:\Program Files\C&F Customer Management\2005_Working_Version\C&F_EventsV6.mdb" "C:\Program Files\C&F Customer Management\2005_Working_Version\C&F Promotions - Event_Maps\*.*"
All it simple does is zip a bunch of files, is there another way I can run these lines of code?
Does your shell statement work when you try to invoke other programs? Try setting the path to point to your calculator program (calc.exe) and see if it will bring it up. Once we know the results, we can go from there.


Rollin
Yes the shell command will start any other .exe file, such as the calc.exe.
Sometimes windows doesn't recognize its own technology and has trouble with long file names -- especially if there is an embedded space. Try replacing the path with an 8.3 compliant one. Usually, the 8.3 name is the first 6 non-space characters and a ~1. So 'Program Files' becomes Progra~1. I'm not sure how the command interpreter will interpret the ampersand in the second node of your path name but you can do a dir /x at the command line and it will give you the proper format.
Just confirmed 'C&F Customer Management' becomes C&FCUS~1 in 8.3 format.
to "SHELL" a batch file you must call it.
shell "c:\mybatchfile.bat" will not work
shell "CALL c:\mybatchfile.bat" will work
He's right you either have to use the CALL or Open function before using a file in code.
Plus if you put the file you are opening in the executables directory you can use the App.Path function which is extremely convenient in code.
1 - 12 of 12 Posts
Status
Not open for further replies.
Top