0

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
B_Rox
  • 25
  • 4
  • The code you posted would not have raised the error you claim it does. Please create a [mcve] 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 Apr 07 '19 at 09:01
  • 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 Apr 07 '19 at 09:07
  • 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 Apr 08 '19 at 07:10

1 Answers1

1

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
Noodles
  • 264
  • 2
  • 3