How do I run a DOS command in WSH?

John Savill

January 5, 2000

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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

DIM objShell
set objShell = wscript.createObject("wscript.shell")
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 closesthe command window after the command is completed. The actual command set var=hellojust creates an environment variable called var set to hello.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like