是否可以附加到另一个控制台应用程序并通过GetConsoleHistoryInfo查看它的命令历史记录?我已经通过DllImport尝试了托管代码,但是从我传入的CONSOLE_HISTORY_INFO结构中,我不知道接下来要去哪里获取命令历史记录。相关代码:
[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_HISTORY_INFO
{
public uint cbSize;
public uint HistoryBufferSize;
public uint NumberOfHistoryBuffers;
public uint dwFlags;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleHistoryInfo(ref CONSOLE_HISTORY_INFO ConsoleHistoryInfo);
static void Main(string[] args)
{
var chi = new CONSOLE_HISTORY_INFO();
chi.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(CONSOLE_HISTORY_INFO));
FreeConsole();
AttachConsole(p.Id); // where p is some known console process
chi = new CONSOLE_HISTORY_INFO();
GetConsoleHistoryInfo(ref chi);
}
chi
包含历史记录缓冲区大小和此后的历史记录缓冲区数量,但我不知道如果可能的话,该信息如何获取命令历史记录。