Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wsh

vbscript

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?

like image 906
coryvb123 Avatar asked Feb 24 '12 15:02

coryvb123


1 Answers

Try this

Set oShell = CreateObject("WScript.Shell")

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

oShell.Run(strCmd)

Set oShell = Nothing
like image 153
Mcbeev Avatar answered Nov 15 '22 11:11

Mcbeev