VBScript WScript.Shell Run() - 系统找不到指定的文件 [英] VBScript WScript.Shell Run() - The system cannot find the file specified
问题描述
我正在尝试编写一个使用 WScript.Shell Run() 方法的 VBScript (.vbs) 脚本,但似乎 Run() 找不到我的文件我进来了.
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.
我已将我的脚本归结为以下可重现结果的代码.这可以复制到文本编辑器,保存为 test.vbs 并运行.type 命令只是输出传入文件中的文本.
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
如果您要直接从 CMD 提示符运行 Run() 中的代码,它工作正常.但是当它从 .vbs 脚本内部运行并使用 Run() 时,它给了我以下错误:
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.
我可以使用 Run() 运行其他命令就好了,但是当我尝试传入路径时却失败了.顺便说一下,Exec() 失败并出现相同的错误.有什么想法吗?
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?
推荐答案
试试这个
Set oShell = CreateObject("WScript.Shell")
strCmd = "cmd /K type C:\inetpub\wwwroot\iisstart.htm"
oShell.Run(strCmd)
Set oShell = Nothing
这篇关于VBScript WScript.Shell Run() - 系统找不到指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!