public static void ClearConsoleHistory() { var chi = new CONSOLE_HISTORY_INFO(); chi.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(CONSOLE_HISTORY_INFO)); if (!GetConsoleHistoryInfo(chi)) { return; } var originalBufferSize = chi.BufferSize; chi.BufferSize = 0; if (!SetConsoleHistoryInfo(chi)) { return; } chi.BufferSize = originalBufferSize; if (!SetConsoleHistoryInfo(chi)) { return; } }
public static extern bool SetConsoleHistoryInfo( CONSOLE_HISTORY_INFO ConsoleHistoryInfo );
static extern bool GetConsoleHistoryInfo( out CONSOLE_HISTORY_INFO ConsoleHistoryInfo );
/// <summary> /// Sets the history settings for the calling process's console. /// </summary> /// <param name="ConsoleHistoryInfo">A pointer to a <see cref="CONSOLE_HISTORY_INFO"/> structure that contains the history settings for the process's console.</param> /// <returns>If the function succeeds, returns TRUE, otherwise, retun FALSE.</returns> [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetConsoleHistoryInfo([In] CONSOLE_HISTORY_INFO ConsoleHistoryInfo);