views:

42

answers:

2

I have these 2 files a.vbs and a.bat each has only one line.

a.vbs

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

a.bat

copy c:\blah\y.y c:\

When it works, it runs a.bat quietly in the background, which does the file copy.

I can do start..run...a.vbs a.bat That works. I can open a command prompt and do wscript a.vbs a.bat

But the thing that doesn't work, is this

start...run...wscript a.vbs a.bat

if I put an msgbox in a.vbs, it's clear that runs. But it looks like a.bat doesn't run when using that method..

Howcome that form doesn't work?

+1  A: 

When WScript.Arguments(0) is not a full path, a.bat needs to be in the current directory.

You can check the current directory with:

WScript.Echo WScript.CreateObject("WScript.Shell").CurrentDirectory

If a.bat is always in the same folder as a.vbs, you can use a full path:

set fso=WScript.CreateObject("Scripting.FileSystemObject")
thepath=fso.BuildPath(fso.GetParentFolderName(WScript.ScriptFullName),"a.bat")
WScript.Echo thepath
Anders
hmm, I think your general point has cottoned onto the general problem.. making sure I used absolute paths everywhere. wscript c:\blah\inv.vbs c:\blah\a.bat and absolute paths with the copy command within the bat..very mundane..nevertheless, I will try to isolate things further and add if I find anything.
barlop
well, I can't seem to reproduce the problem.. I had to rename the files at one point. I tried changing them to absolute paths, it seems to work now.. and when I change many of those paths back , it still works..wscript c:\blah\inv.vbs a.bat (as you say, a.bat in the same dir - which I had infact)and a.bat doesn't need absolute paths in the file copy. I don't know exactly what was going wrong. Why wscript with it didn't work but without did work. But, the problem was in the area you said.. and I see how the code you provided helps to see what's going on too.
barlop
I see that when not specifying a path to the vbs file, then, doing it with wscript, then it will find any vbs file in the path, whereas with wscript it only looks in %userprofile%. But that wasn't the cause of the behaviour, since the vbs file was in a directory that wasn't in the path.
barlop
A: 

Why are you using a vbscript just to call a .bat? Start --> Run --> a.bat

If you have to do it that way, do Start --> Run --> cscript a.vbs a.bat

gWaldo
That method , doing it within the vbs file, runs the bat or whatever command, in the background without opening up a command window. Infact, my question mentions that.
barlop