简体   繁体   English

清除控制台命令历史记录C#

[英]Clear Console Command History C#

I'm writing some software which is password protected. 我正在写一些受密码保护的软件。 When the user starts the program, they enter a password (which is blacked out when typing it). 当用户启动程序时,他们输入密码(在键入密码时会涂黑)。 Then the program changes to a command line interface. 然后程序更改为命令行界面。

The problem is, you can scroll through command history, including the entered password in plaintext. 问题是,您可以滚动浏览命令历史记录,包括以明文形式输入的密码。 How can I clear console history programmatically? 如何以编程方式清除控制台历史记录?

I've attempted the solutions found in this post . 我已经尝试了这篇文章中找到的解决方案。

After trying Svish's answer on the same post , it simply did not work. 同一帖子上尝试Svish的答案 ,它根本没有用。 I used Process.Start("doskey","/reinstall") and all it did was open a command prompt window. 我使用了Process.Start("doskey","/reinstall") ,它所做的只是打开命令提示符窗口。

Hans Olsson's answer didn't work either; 汉斯·奥尔森的答案也没有用。 I got an AccessViolation , and there is no good explanation on how to use it. 我有一个AccessViolation ,关于如何使用它没有很好的解释。 Trying to use FreeConsole doesn't work either, because after freeing and reallocating I can no longer use Console.WriteLine . 尝试使用FreeConsole也不起作用,因为释放并重新分配后,我将无法再使用Console.WriteLine I get an IOException: The method is not supported. 我收到IOException: The method is not supported.

Sending the keystrokes Alt+F7 to the console will clear it per this documentation. 根据文档,将击键Alt + F7发送到控制台将清除它。 You can automate the sending of these keystrokes by using test automation software built into visual studio: 您可以使用Visual Studio中内置的测试自动化软件来自动发送这些击键:

using Microsoft.VisualStudio.TestTools.UITesting;

    Keyboard.SendKeys("%{F7}")

I ended up changing the authentication method. 我最终更改了身份验证方法。 It now retrieves the unique serial number of the BIOS/Motherboard. 现在,它检索BIOS /主板的唯一序列号。 The serial numbers are now on a secure server and are retrieved by the program. 现在,序列号位于安全的服务器上,并由程序检索。 If the serial is found then the execution will continue. 如果找到了序列号,则将继续执行。 If not, the execution will halt. 如果没有,执行将停止。

If people in the company need access to the program, they'll run the program, get access denied (with the serial number in the "access denied" statement), give the admin the serial number, and they'll put it in the system. 如果公司中的人员需要访问该程序,则他们将运行该程序,拒绝访问(序列号在“拒绝访问”语句中),为管理员提供序列号,然后将其放入系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM