Execute DOS command from VBScript

2019-04-07 13:13发布

问题:

How I can Execute a DOS 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:

Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "cmd cd /d C:dir_test\file_test & sanity_check_env.bat arg1"


回答2:

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

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



回答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.



标签: vbscript cmd dos