主页面代码
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Client
{
public partial class Form_Test : Form
{
private string encryptComputer = string.Empty;
private bool isRegist = false;
private const int timeCount = 30;
public Form_Test()
{
InitializeComponent();
}
private void Form_Test_Load(object sender, EventArgs e)
{
//加载
string computer = GetComputerInfo();
encryptComputer = new EncryptionHelper().EncryptString(computer);
if (CheckRegist() == true)
{
lbRegistInfo.Text = "已注册";
}
else
{
lbRegistInfo.Text = "待注册,运行十分钟后将自动关闭!";
RegistFileHelper.WriteComputerInfoFile(encryptComputer);
TryRunForm();
}
}
/// <summary>
/// 试运行窗口
/// </summary>
private void TryRunForm()
{
Thread threadClose = new Thread(CloseForm);
threadClose.IsBackground = true;
threadClose.Start();
}
private bool CheckRegist()
{
EncryptionHelper helper = new EncryptionHelper();
string md5key = helper.GetMD5String(encryptComputer);
return CheckRegistData(md5key);
}
private bool CheckRegistData(string key)
{
if (RegistFileHelper.ExistRegistInfofile() == false)
{
isRegist = false;
return false;
}
else
{
string info = RegistFileHelper.ReadRegistFile();
var helper = new EncryptionHelper(EncryptionKeyEnum.KeyB);
string registData = helper.DecryptString(info);
if (key == registData)
{
isRegist = true;
return true;
}
else
{
isRegist = false;
return false;
}
}
}
private void CloseForm()
{
int count = 0;
while (count < timeCount && isRegist == false)
{
if (isRegist == true)
{
return;
}
Thread.Sleep(1