0
votes

I have a batch file that is save in a shared drive (S:) and I am trying to use vbscripts createobject method to create a shell script to run my batch file. My current vbscript is:

<script language="VBScript">
Sub zeprint()
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.CurrentDirectory = "s:"
oShell.Run "s:\batprint.bat"
Set oShell = Nothing
End Sub
</script>

Then in some html I have, I created a button and set onclick="zeprint()". I know the button works because I use to have it assigned to window.print();. I have been searching all over for the answer to this but cannot seem to figure out why it isn't working. The batch file also runs correctly when manually ran from the command prompt. This leads me to believe that it is a problem with the vbscript.

Any help would be appreciated.

3
Perhaps you have to use Function .... End Function instead of Sub .. End Sub. If I use VBS I use functions, Subs I use only in VBA.ReFran
Do you get an error?JOATMON
wait are you running this from HTML in a browser?JOATMON
I am using this in an asp file that uses htmluser6461470

3 Answers

0
votes

This worked for me:

Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "c:\test.bat"

or use

oShell.run "test.bat"

if the VBS and the BAT are in the same location.

It failed when it could not find the location of the .bat file.

0
votes

You need to use the absolute path of the destination and not the drive letter. Also make sure the device where the path destination is does not have a windows configuration for energy light saving and disk turning off after a couple of minutes.

0
votes

Please see below - change "CALC" to "C:\Batchfile.bat" etc:

Set oShell = WScript.CreateObject("WSCript.shell")

a=msgbox("Run Calculator?" , vbYesNo + vbQuestion , "Run Calc?")

if a = vbyes then

oShell.run "CALC"

else

end if