Search code examples
silverlightc#-4.0silverlight-4.0comcomautomationfactory

COM Automation WScript.Shell Echo command not working


Hi I am trying to run an echo command using AutomationFactory but I get this error:

"The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"

This is the code that I'm using:

dynamic shell = System.Runtime.InteropServices.Automation.AutomationFactory.CreateObject("WScript.Shell");
shell.Run("echo xyz");

I want to be able to do this:

shell.Run("echo xyz >> C:\xyz.txt")

I also tried shell.Echo("xyz"); But I get MissingMemberException.


Solution

  • echo is a shell built-in, not a command, in the same way that dir or rmdir are. You need to execute them through the command interpreter:

    shell.Run("cmd /c echo xyz >> C:\xyz.txt")