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

Posted on 2006-03-27
Last Modified: 2008-01-09

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!

Pinky ^ - ^
Question by:pinkytam
    LVL 6

    Expert Comment

    Hi Pinky,

    The Shell.Run command does a shell-execute on your command-line.  Your command-line contains dos commands (commands internal to 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.

    LVL 6

    Expert Comment

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


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


    Author Comment

    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~

    LVL 6

    Accepted Solution

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


    Author Comment

    Yeah, it works!!
    Million Thanks~ DT~

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now