There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
VB6 Using Shell Command


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
mattpfc's Avatar
Junior Member with 6 posts.
 
Join Date: Jul 2005
03-Jul-2005, 01:57 PM #1
VB6 Using Shell Command
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.

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
Aftab's Avatar
Member with 58 posts.
 
Join Date: Oct 2003
04-Jul-2005, 12:24 PM #2
File Not Found
I apologise if I'm being stupid, but are you sure the file is named zipper.exe and not zipper.bat.
mattpfc's Avatar
Junior Member with 6 posts.
 
Join Date: Jul 2005
04-Jul-2005, 01:15 PM #3
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
Aftab's Avatar
Member with 58 posts.
 
Join Date: Oct 2003
04-Jul-2005, 05:31 PM #4
File not found
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.
asbo's Avatar
Senior Member with 510 posts.
 
Join Date: Sep 2001
Location: who really knows anymore?
Experience: Advanced
04-Jul-2005, 09:11 PM #5
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's Avatar
Junior Member with 6 posts.
 
Join Date: Jul 2005
05-Jul-2005, 03:22 PM #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?
Rollin_Again's Avatar
Distinguished Member with 2,834 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
06-Jul-2005, 01:13 PM #7
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's Avatar
Junior Member with 6 posts.
 
Join Date: Jul 2005
06-Jul-2005, 03:49 PM #8
Yes the shell command will start any other .exe file, such as the calc.exe.
coderitr's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
06-Jul-2005, 04:17 PM #9
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.
coderitr's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
06-Jul-2005, 04:19 PM #10
Just confirmed 'C&F Customer Management' becomes C&FCUS~1 in 8.3 format.
niftienev's Avatar
Computer Specs
Junior Member with 1 posts.
 
Join Date: May 2007
Experience: Advanced
16-May-2007, 12:10 AM #11
to "SHELL" a batch file you must call it.
shell "c:\mybatchfile.bat" will not work
shell "CALL c:\mybatchfile.bat" will work
DrewUberAlles's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: May 2007
Experience: Intermediate
21-May-2007, 09:48 PM #12
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.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:53 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.