WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: keslaa on August 07, 2014, 05:07:52 AM

Title: Executing a VB Script from WinBatch
Post by: keslaa on August 07, 2014, 05:07:52 AM
What would be the easiest way to get this accomplished? I am under a time crunch to get this done. Next month, I will be completing the conversion of the VB script into a WinBatch script but right now I just need to call it. I have been using:
runwait("cscript.exe","<ScriptName>.vbs")
but that just flashes a DOS box and then moves on with the remaining lines. The VB script has a number of steps inside, including an uninstall of a previous version of some software and then an install of the newer version of said software. All in all, it should take a couple of minutes to complete. Any ideas?
Title: Re: Executing a VB Script from WinBatch
Post by: td on August 07, 2014, 07:13:23 AM
Try adding the full path to your VBS script file.

For example:
Code (winbatch) Select

RunWait("cscript.exe",'"c:\projects\batdll\test\Test.vbs"')
Title: Re: Executing a VB Script from WinBatch
Post by: keslaa on August 07, 2014, 07:18:32 AM
Quote from: td on August 07, 2014, 07:13:23 AM
Try adding the full path to your VBS script.

I tried that as well. Either way, the VB script will be sitting in the same folder as the WinBatch script calling it, so it shouldn't be an issue. So, "cscript.exe" is the correct executable to call?
Title: Re: Executing a VB Script from WinBatch
Post by: td on August 07, 2014, 08:01:59 AM
Adding the path may or may not be necessary even if the vbs script is located in the same directory as your WinBatch script.  It depends on how your script is started and what the script does before you attempt to launch cscript.exe.  It also is a good idea to use path information like that supplied by the DirScript function because the Windows default file search order can be altered programmaticly or via registry settings.

Cscript.exe is the command shell scripting host executable that loads the VBS interpreter dll based on the file extension of the script so yes, it is the correct executable.  You can also use wscript.exe which is the Windows GUI executable version of the host. In fact, you could probably get by with not specifying an executable at all using RunWait('"':DirScript():'Test.vbs"',""), assuming the the file extension is registered with the shell. I tried both this method and the previous method with a test vbs script on my system and both worked as expected.

Which version of Windows are you using on the system running your script, what type of user account are you launching the script from and is UAC enabled on this system?  It could be that your vbs script is failing because of some permission issue.