How do I run a DOS command in WSH?

A. Its possible to run a DOS command from inside a WSH program using the following:

DIM objShell<br>
set objShell = wscript.createObject("")<br>
iReturn = objShell.Run("cmd.exe /C set var=hello", 1, TRUE)

You could use %Comspec% variable instead of cmd.exe if you wish. The /C closes the command window after the command is completed. The actual command set var=hello just creates an environment variable called var set to hello.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.