今天又有一个新项目:实现软件激活功能并且附带拷贝功能。
话不多说,直接上代码.
Form1:激活与判断模块:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
using Microsoft.Win32;
namespace 激活实现
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int First_Count = 1;
private void Form1_Load(object sender, EventArgs e)
{
try
{
Int32 tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\HARDWARE\\Imposterstudiosoft", "UserTimes", 0);
if (tLong > 0)
{
label1.Text = "许可证状态:已应用产品密匙"; button1.Enabled = true; button2.Visible = false; label2.Visible = false;
textBox1.Visible = false;
}
else
{
label1.Text = "许可证状态::未激活\n请立即使用产品密匙激活"; button2.Visible = true; button1.Enabled = false; label2.Visible = true;
textBox1.Visible = true;
}
}
catch
{
RegistryKey hklm = Registry.LocalMachine;
RegistryKey software = hklm.OpenSubKey("HARDWARE", true);
RegistryKey main = software.CreateSubKey("Imposterstudiosoft");
RegistryKey ddd = main.CreateSubKey("简信2");
Registry.SetValue("HKEY_LOCAL_MACHINE\\HARDWARE\\Imposterstudiosoft", "UserTimes", First_Count, RegistryValueKind.DWord);
}
}
private void button2_Click(object sender, EventArgs e)
{
Int32 tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\HARDWARE\\Imposterstudiosoft", "UserTimes", 0);
if (textBox1.Text == "T83GX")
{
MessageBox.Show("所选项的激活已经完成,请重新启动程序", "RegManagementTool Script Host");
int Times = tLong + 1;
Registry.SetValue("HKEY_LOCAL_MACHINE\\HARDWARE\\Imposterstudiosoft", "UserTimes", Times); Application.Exit();
}
else
{
MessageBox.Show("输入的字符串可能不正确或激活失败", "RegManagementTool Script Host");
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();Form2 frm2 = new Form2();frm2.Show();
}
}
}
Form2:复制与读取目录下的文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
using Microsoft.Win32;
namespace 激活实现
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("You can Close for this Program?", "Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
选项显示框.Items.Remove(选项显示框);
选项显示框.ClearSelected();
fbd_Dialog.ShowDialog();
textBox1.Text = fbd_Dialog.SelectedPath;
DirectoryInfo dir = new DirectoryInfo(textBox1.Text);
FileInfo[] f = dir.GetFiles();
for (int i = 0; i < f.Length; i++)
{
选项显示框.Items.Add(f[i]);
System.Threading.Thread.Sleep(50);
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty)
{
MessageBox.Show("文件夹目录不能为空!");
}
else
{
if (textBox2.Text == string.Empty)
{
MessageBox.Show("要拷贝的目录不能为空!");
}
else
{
foreach (object o in 选项显示框.SelectedItems)
{
File.Copy(textBox1.Text + "\\" + o.ToString(), textBox2.Text + "\\" + o.ToString());
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
fbd_Dialog.ShowDialog();
textBox2.Text = fbd_Dialog.SelectedPath;
}
private void 选项显示框_Click(object sender, EventArgs e)
{
button3.Text = "复制选中文件";
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Environment.CurrentDirectory;textBox2.Text = Environment.SystemDirectory;
}
}
}
运行效果展示:(密匙T83GX)
激活前的Form1:
激活后:
Form2:
这是本文的全部内容。