通过Process打开notepad.exe后,如何向记事本中写入信息呢?
代码如下:
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.RedirectStandardError=true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.StandardInput.WriteLine(" 计算结果如下:");但打开的记事本中为空,没有想写入的字符,请问该如何实现改功能?
代码如下:
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.RedirectStandardError=true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.StandardInput.WriteLine(" 计算结果如下:");但打开的记事本中为空,没有想写入的字符,请问该如何实现改功能?
解决方案 »
- 大家好,我问个WebService初始化的
- 如何遍历tabcontrol控件的所有的tabpage中的所有控件?
- sql语法,急用
- 求C#DES加密的key可为任意长度字符或为空代码
- 请教下,关于安装vs2008的问题
- 救命啊!我想在xml里取某个节点的值,但总是报错,请大家帮忙啊!
- Socket问题,用过NetworkStream.DataAvailable或Socket.Available的进来看看
- 急急急--我在DataGrid1模板里面又放了一个DataGrid2,怎样响应DataGrid2的索引改变事件以及其他事件!
- 寻求插件或者开源软件——3D模型生成工具
- 总算写完一个C#类,一看表,发现已经是2002年了。。。
- 要求输出选票统计结果及最终哪位候选人 使用C#实现
- 哪位亲有Visual Studio2005入门.Net系列视频教程?如能共享,非常感谢!
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);
[DllImport("User32.DLL")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
public const uint WM_SETTEXT = 0x000C; System.Diagnostics.Process Proc;
try
{
Proc = new System.Diagnostics.Process();
Proc.StartInfo.FileName = "notepad.exe";
Proc.StartInfo.UseShellExecute = false;
Proc.StartInfo.RedirectStandardInput = true;
Proc.StartInfo.RedirectStandardOutput = true;
Proc.Start();
}
catch
{
Proc = null;
}
if (Proc != null)
{
while (Proc.MainWindowHandle == IntPtr.Zero)
{
Proc.Refresh();
}
IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);
SendMessage(vHandle, WM_SETTEXT, 0, "Message");
}
}