VB6 Using Shell Command

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

mattpfc

Thread Starter
Joined
Jul 3, 2005
Messages
6
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
 
Joined
Oct 15, 2003
Messages
72
I apologise if I'm being stupid, but are you sure the file is named zipper.exe and not zipper.bat.
 

mattpfc

Thread Starter
Joined
Jul 3, 2005
Messages
6
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
 
Joined
Oct 15, 2003
Messages
72
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.
 
Joined
Sep 21, 2001
Messages
507
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
 

mattpfc

Thread Starter
Joined
Jul 3, 2005
Messages
6
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?
 
Joined
Sep 4, 2003
Messages
4,915
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
 

mattpfc

Thread Starter
Joined
Jul 3, 2005
Messages
6
Yes the shell command will start any other .exe file, such as the calc.exe.
 
Joined
Oct 12, 2003
Messages
3,015
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.
 
Joined
May 16, 2007
Messages
1
to "SHELL" a batch file you must call it.
shell "c:\mybatchfile.bat" will not work
shell "CALL c:\mybatchfile.bat" will work
 
Joined
May 9, 2007
Messages
29
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top