0
votes

I am trying to parse the command echo msg>com4 to CMD from web application. I was tried different ways but I am not able to do it. In this case I want to show the results also without popping CMD run and close it.

Here is my script:

<html>
<head>
<script language="vbscript" type="text/Vbscript"> 
Function cmdRun( )
    Dim shell, fileName
    Set shell = CreateObject("WScript.Shell")
    Set proc = shell.Exec("echo msg>com4")
End Function
</script>
</head>

<body>
    <input type="button" onclick="cmdRun()" value="copy" />
</body>
</html>

Sometimes it is showing error "VBA Script 424: object required". When I used cscript that also shows the error.

1
The code you posted would not have raised the error you claim it does. Please create a minimal reproducible example demonstrating the problem you're facing, then edit your question and post that code along with the complete, unaltered error that code raised. Copy/paste. Post a screenshot of the error message if you can't copy/paste it as text. Do not paraphrase. Do not type from memory. - Ansgar Wiechers
Also, running echo msg>com4 is not going to work, b/c both echo and the redirection operator are CMD-builtin features that aren't available outside of CMD. - Ansgar Wiechers
There is no such thing as a VBA Script Error, please copy errors correctly to avoid typos if entered manually. The error is a VBScript Error, a very common one. - user692942

1 Answers

1
votes

If you are running as a web application, ie with a page open from the internet, you man not run programs or use activex controls that can affect the system.

On a web page usesafesubset is true.

See my answer here - What can't I use when UseSafeSubset is true?

Also VBScript no longer works on web pages. Only on local pages and intranet sites.

If you change your script to a local VBS file and run it with CScript.exe and use wscript.echo to print.

cmd /c cscript //nologo MyVbs.vbs > Com4