-3

I can't run the file cmd.exe /k "...", I get the error 800a0401! I used the method set a = WScript.Createobject("WScript.Shell")

Error on line 3, character 14.

dim a
set a = WScript.CreateObject("WScript.Shell")
a.run cmd /k "@echo off && echo Hello World && pause && exit"

I tried to write a = nothing at the end of the code and replaced cmd with cmd.exe Before a I put dim a Nothing helped

1
  • 1
    The Run() method expects a valid string which starts and ends with double quotes, this is VBScript 101. As the Documentation says - ""String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file.. Commented Dec 4, 2024 at 18:18

1 Answer 1

0

Your syntax for calling the a.run method is incorrect.

It should be:

set a = WScript.CreateObject("WScript.Shell")
a.run "cmd /k ""@echo off && echo Hello World && pause && exit"""

The whole command needs to be within doublequotes. You can then escape the inner doublequotes by doubling them.

Sign up to request clarification or add additional context in comments.

3 Comments

This is a quick flag as duplicate and move on, not the first or last to not understand basic VBScript syntax.
Uniquely, there were no quotes on the outside. I didn't find a good duplicate immediately to really bring the point across. Your comment about the documentation is probably going over OP's head, I assume they just want to get things to work and don't even know what a "string value" is, let alone how its escaping rules work. You can just downvote this answer if you disagree.
In which case, not the place to ask.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.