We help IT Professionals succeed at work.

WshShell.Run got error: The system cannot find the file specified

pinkytam
pinkytam asked
on
Medium Priority
3,700 Views
Last Modified: 2008-01-09
Hello,

I have written a short vbs and try to run in command prompt in windows:

Dim iReturn
Dim WshShell

WScript.Echo "-> Start"

Set WshShell = WScript.CreateObject("WScript.Shell")

iReturn = WshShell.Run ("echo hello", 1, TRUE)

However, I've got this error message:
C:\Documents and Settings\My Documents\test2.vbs(8, 1) (null): The system cannot find the file specified.

Do anyone know what's wrong with my script?
Thank you!

Regards,
Pinky ^ - ^
Comment
Watch Question

Hi Pinky,

The Shell.Run command does a shell-execute on your command-line.  Your command-line contains dos commands (commands internal to Command.com or Cmd.exe) and they are not directly executable.

From your Windows Start menu, select Run.
Anything you can make work from here you can put between the "" of your Run command.
If I try to run "echo hello" then I'm told "Windows cannot find 'echo'."  ie.  Cannot find the file specified.

Put your dos commands in a batch file and run that instead.

Regards,
DT.
eg.  Create a text file called MyCmds.cmd and enter one line;  echo hello
Now try,
    iReturn = WshShell.Run ("MyCmds.cmd", 1, TRUE)

Or

Maybe all you really want is,
    iReturn = WshShell.Run ("CMD /K echo Hello", 1, TRUE)

Author

Commented:
Hi DeadlyTrev,

Thanks for your prompt reply~
I've modified my code and it works, but how can I close the opened command prompt? If i keep it open, it seems the vbs will never exit unless I close the comand prompt manually~

Pinky
Use CMD /C then the command prompt will execute a single command and exit.   CMD /K will execute the command and remain open.

DT.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Yeah, it works!!
Million Thanks~ DT~
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.