开发者

problem running start..run..wscript a.vbs a.bat

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开发者_JS百科 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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜