Why does my console application have command history?
you can change this behaviour of windows programmatically by calling SetConsoleHistoryInfo
with a correctly setup CONSOLE_HISTORY_INFO
structure... there seems to be no managed class/method so you will have to use DllImport
etc.
http://msdn.microsoft.com/en-us/library/ms686031%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms682077%28v=VS.85%29.aspx
IF need be - several other aspects of the console can be handled in a managed way - see c# console, Console.Clear problem
The history feature is built into the Windows Command shell, it is not a feature of your application. AFAIK there's no way to disable this in your code as it's specific to the Windows Shell Environment (unless there's a setting that can be changed, which there probably is)
You could possibly override the default behavior by using a key listener to get all up arrow keypresses and execute your own code, that way the event doesn't drop down to the shell to handle.
Yes, this is a feature of the console subsystem, not your application. To change it, click the console's control box (top left), properties, options tab: "Command history." The default is 50 items, 4 buffers. Supposedly this can be configured programmatically with DOSKEY from the command line, but a few minutes tinkering didn't lead me anywhere.
ALT+F7
will clear the command history, as will executing the command DOSKEY /reinstall
. I tested in Windows 7.
Update: The corresponding Win32 API call is SetConsoleHistoryInfo
and the p/invoke signature can be found at http://pinvoke.net/default.aspx/kernel32/SetConsoleHistoryInfo.html