0

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.

Matt Bridges
  • 48,277
  • 7
  • 47
  • 61
sonu
  • 164
  • 2
  • 8
  • The answer is below, but I really do need to ask why you're going through such trouble to do: System.IO.File.AppendAllText(@"C:\xyz.txt", "xyz"); – Michael Edenfield Oct 17 '11 at 17:56
  • I don't think silverlight allows you to do that. It will give you a security exception. You cannot directly access the file system. Even if you are running an Out-of-Browser, elevated trust application – sonu Oct 17 '11 at 18:38

1 Answers1

2

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")
Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117