VBScript WScript.Shell Run() - The system cannot find the file specified

China☆狼群 提交于 2019-12-06 03:25:17

问题


I'm trying to write a VBScript (.vbs) script that uses the WScript.Shell Run() method, but it seems as though Run() can't find the file I'm passing in.

I've boiled my script down to the following code that will reproduce the results. This can be copied to a text editor, saved as test.vbs and ran. The type command simply outputs the text inside the file passed in.

Dim WShell
Set WShell = WScript.CreateObject("WScript.Shell")

WShell.Run("type C:\inetpub\wwwroot\iisstart.htm")

Set WShell = Nothing

If you were to run the code in Run() directly from the CMD prompt, it works fine. But when it's run from inside a .vbs script and using Run(), it gives me the following error:

Test.vbs(4, 1) (null): The system cannot find the file specified.

I can run other commands using Run() just fine, but when I try to pass in a path it fails. Exec() fails with the same error by the way. Any ideas?


回答1:


Try this

Set oShell = CreateObject("WScript.Shell")

strCmd = "cmd /K type C:\inetpub\wwwroot\iisstart.htm"

oShell.Run(strCmd)

Set oShell = Nothing


来源:https://stackoverflow.com/questions/9432901/vbscript-wscript-shell-run-the-system-cannot-find-the-file-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!