# help with vbscript and batch file



## empleh (Jan 16, 2009)

Can anyone help with my issue please.
I am trying to run a file initiated from vbscript with the following
Sub RunProgram 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "O:\Engrave\D00800bk.src"
End Sub
The file extension .src is associated through the file types tab, to open with the following batch file code below.
____________________________________________________________
file .bat code below :
@ECHO ON
%BRAVO3_ROOTDIR%\bin\exec.exe NCG %1 %2 %3 %4 %5 %6 %7 %8

1]____________________________________________________________
if i double click D00800bk.src (actual file to run ) command window shows:
O:\Engrave>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
2]____________________________________________________________
if run from script file command window shows
C:\Documents and Settings\username\Desktop>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
3]____________________________________________________________
if double click .bat file command window shows:
C:\Bravo3\bin\exec.exe NCG 
____________________________________________________________
How can i duplicate option 1] in vb or vbscript
O:\Engrave> C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
how is the path O:\Engrave> passed to the bat file through association, can it be done through code?
Thanks


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!



empleh said:


> Can anyone help with my issue please.
> I am trying to run a file initiated from vbscript with the following
> Sub RunProgram
> Set objShell = CreateObject("Wscript.Shell")
> ...


Are you saying you associated the .src extension with cmd.exe? or with the file name of your batch file?


empleh said:


> 1]____________________________________________________________
> if i double click D00800bk.src (actual file to run ) command window shows:
> O:\Engrave>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
> 2]____________________________________________________________
> ...


Option one shows this is the command executed:
*C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src*
Option two when you run the vb script shows this is the command:
*C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src*

These are identical, so the vbs script is already doing what you want it to do, at least as I understand what you are asking.



empleh said:


> 3]____________________________________________________________
> if double click .bat file command window shows:
> C:\Bravo3\bin\exec.exe NCG


Option 3 is to be expected as you did not provide any command line options to the file, so the variables %1-%8 are all null



empleh said:


> O:\Engrave> C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
> how is the path O:\Engrave> passed to the bat file through association, can it be done through code?
> Thanks


Not sure how you did the association, but using an association does this:
program "%1"

so O:\Engrave\D00800bk.src is passed as a command line variable to the program.

so to run the batch file you need to open a Command prompt, switch to the folder the batch file is in (unless it's on the path) then type the following:
batfilename O:\Engrave\D00800bk.src

I'm not familiar with Bravo3, and Google was less than helpful.
What is it you are trying to do?
You have 8 batch variables on the command line, are you trying to pass 8 filenames to the program? Or a filename and other command line options?
Was the *.src* extension originally associated with *C:\Bravo3\bin\exec.exe*?

HTH

Jerry


----------



## empleh (Jan 16, 2009)

TheOutcaste said:


> Welcome to TSG!
> 
> Are you saying you associated the .src extension with cmd.exe? or with the file name of your batch file?
> 
> ...


Hi Jerry,
Thanks for the reply. When i run the script it was showing:-
C:\Documents and Settings\username\Desktop>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
instead of:-
O:\Engrave>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src

Through a little more web surfing and experimenting i found i had to change the directory in dos to O:engrave.

new script=


```
Set objShell = CreateObject("Wscript.Shell")
objshell.CurrentDirectory="O:engrave"
objShell.Run "C:\Bravo3\bin\exec.exe NCG D00800bk.src"
```
Dont know exactly how, but this works now, Cheers anyway
Keith.


----------



## TheOutcaste (Aug 8, 2007)

Glad you got it working Keith. I sure missed what you were saying.


empleh said:


> C:\Documents and Settings\username\Desktop>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src
> instead of:-
> O:\Engrave>C:\Bravo3\bin\exec.exe NCG O:\Engrave\D00800bk.src


The part in blue is part of the prompt in the command window, it shows the current directory.
The part in red is the command that is being executed, and those are identical, so it would seem they would do the same. The part in blue being different is normal for what you were doing in each case, and without knowing what the program actually does, I overlooked it, as the path to the program and the data file were both specified, which usually means the current directory is not relevant.

In this case it would appear that the program, C:\Bravo3\bin\exec.exe, is looking for _other_ files in the same directory that the *.src file is in, and only looks in the current directory, and doesn't check the path to the *.src file.
So, you need to change the current directory in the script so the program can find them.

Hope that helps explain the why of it.

One thing


empleh said:


> ```
> objshell.CurrentDirectory="O:engrave"
> [/quote]
> Your missing the \ after the drive letter.
> ...


----------



## empleh (Jan 16, 2009)

Hi again Jerry,
Your right about the other files in directory. The .src files call other files as subprograms from the same directory (folder). If they are in another folder the program errors out file not found. Thanks for the explanation. Your right about the missing \ , I am on my computer at home and was trying to remember what i did at work ( where i am running this) Just a typo. The program is an old application for cadcam been made to work on windows. The .src file are written in an old language called compactII. I have been toying with making an editor type program with a run button to fire up the program, after editing the src file. Its really long winded how we use it.. open src in notepad, edit src code, close notepad, find file in explorer, double click to run, check results, if not ok repeat process..open src in notepad etc
Cheers
Keith.


----------

