securestring,输入计算机密码打开Notepad

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.ComponentModel;
using System.Diagnostics;
namespace ConsoleApplication2
{

class Test
{

static void Main()
{
SecureString securePwd = new SecureString();
ConsoleKeyInfo key;

Console.Write("Enter password: ");
do
{
key = Console.ReadKey(true);

// 对输入的判断(只有数字和字母)
if (((int)key.Key) >=48 && ((int)key.Key <= 90))
{
// 读取数字和字母
securePwd.AppendChar(key.KeyChar);
Console.Write("*");
}
else if (key.Key == ConsoleKey.Backspace)//判断退格
{
securePwd.RemoveAt(securePwd.Length-1);
Console.Write('\b');
}
// 回车时退出
} while (key.Key != ConsoleKey.Enter);
Console.WriteLine();

//判断密码正确与否,若正确打开记事本
try
{
Process.Start("Notepad.exe", System.Environment.MachineName.Split('-')[0], securePwd, "MYDOMAIN");

securePwd.Dispose();
}
catch (Win32Exception e)
{
Console.WriteLine(e.Message);
};
Console.ReadKey();
}
}
}

posted @ 2014-04-24 17:38  江南小驴  阅读(306)  评论(0编辑  收藏  举报