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.

3
  • 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. Commented Apr 7, 2019 at 9: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. Commented Apr 7, 2019 at 9: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. Commented Apr 8, 2019 at 7:10

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.