VBScript WScript.Shell Run() - 系统找不到指定的文件

cor*_*123 5 vbscript wsh

我正在尝试编写一个使用WScript.Shell Run()方法的VBScript(.vbs)脚本,但似乎Run()无法找到我传入的文件.

我已经将我的脚本简化为以下代码,它将重现结果.这可以复制到文本编辑器,保存为test.vbs并运行.类型的命令只是输出传入的文件中的文本.

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

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

Set WShell = Nothing
Run Code Online (Sandbox Code Playgroud)

如果您直接从CMD提示符运行Run()中的代码,它可以正常工作.但是当它从.vbs脚本内部运行并使用Run()时,它会给我以下错误:

Test.vbs(4, 1) (null): The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

我可以使用Run()运行其他命令就好了,但是当我尝试传入路径时它会失败.顺便说一句,Exec()失败并出现相同的错误.有任何想法吗?

小智 8

试试这个

Set oShell = CreateObject("WScript.Shell")

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

oShell.Run(strCmd)

Set oShell = Nothing
Run Code Online (Sandbox Code Playgroud)