使用匿名管道pipe例子
来源:互联网 发布:linux 安装服务 编辑:程序博客网 时间:2024/06/09 17:06
简单的匿名管道使用
匿名管道发送端代码片段:
using System.Runtime.InteropServices;<span style="white-space:pre"></span> using System.Diagnostics;<pre name="code" class="csharp"><span></span> <span style="font-family: Arial, Helvetica, sans-serif;">using System.IO.Pipes;</span>
<span></span> <span style="font-family: Arial, Helvetica, sans-serif;">using System.IO;</span>
<span style="white-space:pre"></span> Process process = new Process(); AnonymousPipeServerStream pipeStream = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable); StreamWriter sw;
private void SetUpCBTHook() { try { process.StartInfo.FileName = "run32hook.exe"; //将句柄传递给子进程 process.StartInfo.Arguments = pipeStream.GetClientHandleAsString(); process.StartInfo.UseShellExecute = false; process.Start(); //创建匿名管道流实例 sw = new StreamWriter(pipeStream); //销毁子进程的客户端句柄? pipeStream.DisposeLocalCopyOfClientHandle(); sw.AutoFlush = true; //System.Diagnostics.Process.Start("run32hook.exe"); sw.WriteLine("starthook"); } catch (Exception ex) { } }
匿名管道接收端代码:
program.cs
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;using System.IO.Pipes;using System.IO;using System.Runtime.InteropServices;namespace run32hook{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] [DllImport("winhook.dll")] static extern int setHookDll(); [DllImport("winhook.dll")] static extern bool unHookDll(); static void Main(string[] args) { string strPipeHandle = args[0]; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 frm = new Form1(); frm.Text = strPipeHandle; //Application.Run(frm); //setHookDll(); AnonymousPipeClientStream pipeStream = new AnonymousPipeClientStream(PipeDirection.In, strPipeHandle); StreamReader sr = new StreamReader(pipeStream); string line; while (true) { if ((line = sr.ReadLine()) != null) { switch (line) { case "starthook": break; case "unhook": break; case "exit": return; default: Console.WriteLine("default: {0}", line); break; } } } } }}
0 0
- 使用匿名管道pipe例子
- 匿名管道(pipe)
- 【linux】匿名管道pipe
- 同一个进程使用pipe(管道)的例子
- Linux_ pipe 匿名管道 浅解
- Linux_ pipe 匿名管道demo
- linux pipe 管道简单例子
- pipe管道的使用
- angular2--pipe管道使用
- 进程间通信---匿名管道pipe
- C# DOS回显(匿名管道Pipe)
- 使用windowsAPI穿件匿名管道pipe,父子进程间数据传递
- linux系统编程之管道(一):匿名管道(pipe)
- linux系统编程之管道 匿名管道(pipe)
- 匿名管道中的 半双工管道(pipe)
- linux系统编程之管道(一):匿名管道(pipe)
- Linux管道pipe使用实例
- 管道Pipe的初次使用
- AsyncTask与FutureTask运用介绍
- iwebshop sql语句拼接
- 哈希表,二次探测再散列
- openVPN与域控的关联验证 以及问题解决过程
- Android Studio目录结构
- 使用匿名管道pipe例子
- 最基础的KMP模式串匹配
- NSPredicate多条件查询
- git打补丁(patch)
- JS变量重复声明以及忽略var 声明的问题及其背后的原理
- Codeforces Round Intel Code Challenge Final Round C. Ray Tracing
- Slidingmenu侧滑菜单
- Android图像格式类及图像转换方法
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B