running VBS files

D

dimplewathen

Anyone think of a cleaner/nicer/eleganter way of running VBS file in
ASP than this example?

(Goal is to re-use typical VBS code that uses 'wscrip.echo' without
having to re-write everything to use 'response.write'.)


<script language="vbscript" runat="server">

class wscript_class
function echo(s)
response.write(s & "<br>")
end function
function quit()
' do nothing for now
end function
end class

dim wscript
set wscript = new wscript_class

Include "VBSCRIPT_TO_RUN_HERE.vbs"

Function Include (Scriptname)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(Scriptname)
ExecuteGlobal oFile.ReadAll()
oFile.Close
End Function

</script>



Try it with this single line VBS file:

wscript.echo("included vbscript that uses Wscript.Echo")


(The code works; any errors would be from typos introduced while
posting here.)
 
D

Dimple

better version as it works as expected:

<%

class wscript_class
function echo(s)
response.write(s & "<br>")
end function
function quit()
' dummy
end function
end class

set wscript = new wscript_class

function runscript(file)
dim fso,fo,script
set fso = CreateObject("Scripting.FileSystemObject")
set fo = fso_OpenTextFile(file)
script = fo.ReadAll()
fo.Close
execute(script)
end function

%>

<html><head><title>Run Script</title></head>
<body>

<%
runscript("c:\temp\test.vbs")
%>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top