已知的问题
  1. 调试的时候会报IO 异常,非调试环境是正常的
2. Windows 应用程序才可以使用,可以用非windows应用程序包一层
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using windowsApiAcitonSimulation.Win32Action; namespace winFormTest
{
static class Program
{ [DllImport("kernel32.dll", SetLastError = true)]
static extern bool AttachConsole(uint dwProcessId); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle); [DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadConsoleOutputCharacter(IntPtr hConsoleOutput, [Out] StringBuilder lpCharacter, uint length, Coord bufferCoord, out uint lpNumberOfCharactersRead); [StructLayout(LayoutKind.Sequential)]
public struct Coord
{
public short X;
public short Y;
} public static string ReadCharacterAt(int x, int y, int length)
{
IntPtr consoleHandle = GetStdHandle(-); if (consoleHandle == IntPtr.Zero)
{
return null;
}
Coord position = new Coord
{
X = (short)x,
Y = (short)y
};
StringBuilder result = new StringBuilder(length);
uint read = ;
if (ReadConsoleOutputCharacter(consoleHandle, result, (uint)length, position, out read))
{
return result.ToString();
}
else
{
return null;
}
} /// <summary>
/// 关闭进程
/// </summary>
/// <param name="processName">进程名</param>
private static Process GetNgrokProcess(string processName)
{
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
if (item.ProcessName == processName)
{
return item;
}
}
return null;
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{ var process = GetNgrokProcess("ngrok"); //注意要是 Windows 应用程序才可以 AttachConsole成功
var flag = AttachConsole((uint)process.Id); Console.CursorLeft = ;
Console.CursorTop = ;
string content = ReadCharacterAt(, , ); //if (content?.IndexOf("reconnecting") > -1)
//{
// var ptr = WindowsApiHelp.FindWindow("ConsoleWindowClass", @"ngrok.bat");
// if (ptr == IntPtr.Zero)
// {
// ptr = WindowsApiHelp.FindWindow("ConsoleWindowClass", @"选择ngrok.bat");
// }
// var pid = GetCurrentProcessID(ptr);
// WindowsApiHelp.SendMessage(ptr, WindowsMessages.WM_CLOSE, 0, 0);
//} } }
}

 

c# 通过win32 api 得到指定Console application Content的更多相关文章

  1. C#调用Win32 api学习总结

    从.NET平台调用Win32 API Win32 API可以直接控制Microsoft Windows的核心,因为API(Application Programming Interface)本来就是微 ...

  2. Win32 Console Application、Win32 Application、MFC三者之间的联系和区别

    转自:http://blog.csdn.net/c_base_jin/article/details/52304845 在windows编程中,我们或多或少都听说这三个名称,分别是Win32 Cons ...

  3. win32 console application 如何修改图标?

    win32 console application ,不要看这名字高端大气上档次,让你摸不着头脑,其实他就是我们最先学习c语言那种黑色窗口的东西......话说他怎么修改图标呢?第一种方法是:右键-〉 ...

  4. 用vs2008和vs2005创建win32 console application

    http://blog.sina.com.cn/s/blog_4900be890100s735.html 对于经常使用vc6.0的人来说,创建一个win32 console application很简 ...

  5. 重温 Win32 API ----- 截屏指定窗体并打印

    朋友说在一个VC++6.0开发的项目中要增加打印窗体的功能,让帮忙写个代码供其调用. 这么老的IDE当然不想碰了,并且也不喜欢MFC笨拙不清晰的封装.所以决定採用纯Win32 API,然后用C++类简 ...

  6. 【.Net】从.NET平台调用Win32 API

    小序        Win32 API可以直接控制Microsoft Windows的核心,因为API(Application Programming Interface)本来就是微软留给我们直接控制 ...

  7. 控制台——对WIN32 API的使用(user32.dll)

    Win32 API概念:即为Microsoft 32位平台的应用程序编程接口(Application Programming Interface).所有在Win32平台上运行的应用程序都可以调用这些函 ...

  8. C#调用Win32 api时的内存操作

    一般情况下,C#与Win 32 Api的互操作都表现的很一致:值类型传递结构体,一维.二维指针传递IntPtr.在Win32 分配内存时,可以通过IntPtr以类似移动指针的方式读取内存.通过IntP ...

  9. 【C++】从零开始,只使用FFmpeg,Win32 API,实现一个播放器(一)

    前言 起初只是想做一个直接读取视频文件然后播放字符动画的程序.我的设想很简单,只要有现成的库,帮我把视频文件解析成一帧一帧的原始画面信息,那么我只需要读取里面的每一个像素的RGB数值,计算出亮度,然后 ...

随机推荐

  1. PAT 乙级 1040.有几个PAT C++/Java

    题目来源 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位( ...

  2. Exploit Kit——hacker入侵web,某iframe中将加载RIG EK登录页面,最终下载并执行Monero矿工

    RIG Exploit Kit使用PROPagate注入技术传播Monero Miner from:https://www.4hou.com/technology/12310.html 导语:Fire ...

  3. php组合设计模式(composite pattern)

    过十点. <?php /* The composite pattern is about treating the hierarchy of objects as a single object ...

  4. 快速了解前端打包 webpack

    一.介绍 (1)概念 webpack 用于编译 JavaScript 模块,是 JavaScript 静态模块的打包工具.从 webpack v4.0.0 开始,可以不用引入一个配置文件. (2)核心 ...

  5. ECHO命令输出空行的11种方法和效率

    标题: 批处理技术内幕:ECHO命令作者: Demon链接: http://demon.tw/reverse/cmd-internal-echo.html版权: 本博客的所有文章,都遵守“署名-非商业 ...

  6. 图论 - PAT甲级 1013 Battle Over Cities C++

    PAT甲级 1013 Battle Over Cities C++ It is vitally important to have all the cities connected by highwa ...

  7. 用Python打造了一个渗透测试暴力探测器

    资源探测的作用 通过资源探测,我们可以在目标系统中发现文件.目录.活动.服务还有相关的参数,为下一步的行动提供信息参考. 一个开源的模糊测试数据库 https://github.com/fuzzdb- ...

  8. python应用-一组数的最大值,最小值,平均数

    def foo(n): c=[] for _ in range (n): var=randint(60,100) c.append(var) print(c) total=0 max = c[0] m ...

  9. oracle之随机数

    一.首先创建一个测试表 select * from DIM_IA_TEST1 生成随机数 select t.*,rownum rn from  (select * from DIM_IA_TEST1 ...

  10. 利用python jieba库统计政府工作报告词频

    1.安装jieba库 舍友帮装的,我也不会( ╯□╰ ) 2.上网寻找政府工作报告 3.参照课本三国演义词频统计代码编写 import jieba txt = open("D:\政府工作报告 ...