2

我试试这个教程

http://elegantcode.com/2010/02/20/silverlight-4-com-interop-and-the-cool-stuff-you-can-do-with-it/

我需要打开记事本并将文本发送到。我使用这段代码:

using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
    {
        shell.Run(@"C:\windows\notepad.exe"); //you can open anything

        shell.SendKeys(txtTextToSend.Text);
    }

当我开始应用程序时,记事本已经出现,但里面没有文字。

我有什么错。我的系统是W7 64位。谢谢

4

1 回答 1

2

问题是 Run 是一个非阻塞操作,一旦启动进程就会返回。记事本的 UI 可能尚未出现,并且在您的代码调用时将焦点放在其输入区域SendKeys

尝试引入 aThread.Sleep几秒钟以证明这是否正确。

于 2011-02-13T21:29:34.033 回答