10

How I can Execute a cmd command from VBScript (not by .bat file)

For example, I want to execute the following from VBScript:

cd /d C:dir_test\file_test 
sanity_check_env.bat arg1
1
  • 3
    you mean execute dos commands from VBScript? Commented Mar 29, 2011 at 4:18

3 Answers 3

11

To run 'dos' commands you need to instantiate the WScript.Shell object and use it's Run() method:

Set oShell = WScript.CreateObject("WScript.Shell")
oShell.run "cmd cd /d C:dir_test\file_test & sanity_check_env.bat arg1"
Sign up to request clarification or add additional context in comments.

Comments

3

Create WScript.Shell object and invoke Run() method on it.

http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx

Comments

3

Can also invoke oShell.Exec in order to be able to read STDIN/STDOUT/STDERR responses. Perfect for error checking which it seems you're doing with your sanity .BAT.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.