大家好!这是我的第一篇博客。
C#实现激活Windows10,时期一到只需打开单击激活按钮即可。
程序大小:119KB。
实现代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.SqlServer;
using Microsoft.Win32;
using System.Threading;
using System.Diagnostics;
using System.IO;
namespace 远程信息发送器
{
public partial class 主窗口 : Form
{
public 主窗口()
{
InitializeComponent();
this.BackColor = Color.White;
this.Width = 370;
this.Height = 250;
this.StartPosition = FormStartPosition.CenterScreen;//指定窗口初始位置
this.MaximizeBox = false;//最大化
this.MinimizeBox = false;//最小化
this.FormBorderStyle = FormBorderStyle.FixedDialog;//指定边框样式
this.DoubleBuffered = true;//双缓冲技术:使用双缓冲技术绘制窗体,解决闪烁问题
}
private string First_Count = "";
private void 主窗口_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void 主窗口_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
string[] nmb = { "slmgr /ipk " + textBox1.Text, "slmgr /skms kms.chinancce.com" };
for (int a = 0; a < nmb.Length; a++)
{
ExcuteDosCommand(nmb[a]);
}
}
private void ExcuteDosCommand(string cmd)
{
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler(sortProcess_OutputDataReceived);
p.Start();
StreamWriter cmdWriter = p.StandardInput;
p.BeginOutputReadLine();
if (!String.IsNullOrEmpty(cmd))
{
cmdWriter.WriteLine(cmd);
}
cmdWriter.Close();
p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); Application.Exit();
}
}
private void sortProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
}
}
private void 主窗口_Load_1(object sender, EventArgs e)
{
string tLong = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", 0);
listBox1.Items.Add("产品版本(操作系统):" + tLong);
if (tLong == "Windows 10 Professional")
{
textBox1.Text = "VK7JG-NPHTM-C97JM-9MPGT-3V66T";
}
else
{
if (tLong == "Windows 10 Education")
{
textBox1.Text = "YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY";
}
else
{
if (tLong == "Windows 10 Enterprise")
{
textBox1.Text = "XGVPP-NMH47-7TTHJ-W3FW7-8HV2C";
}
else
{
if (tLong == "Windows 10 Education")
{
textBox1.Text = "YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY";
}
else
{
if (tLong == "Windows 10 ProfessionalEducation")
{
textBox1.Text = "YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY";
}
else
{
if (tLong == "Windows 10 ProfessionalWorkstation")
{
textBox1.Text = "8PTT6-RNW4C-6V7J2-C2D3X-MHBPB";
}
else
{
if (tLong == "Windows 10 ServerSolution")
{
textBox1.Text = "WVDHN-86M7X-466P6-VHXV7-YY726";
}
else
{
if (tLong == "Windows 10 Home")
{
textBox1.Text = "TX9XD-98N7V-6WMQ6-BX7FG-H8Q99";
}
else
{
}
}
}
}
}
}
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Environment.Is64BitOperatingSystem)
{
listBox1.Items.Add("操作系统位数:X64");
timer1.Enabled = false;
}
else
{
listBox1.Items.Add("操作系统位数:X32");
timer1.Enabled = false;
}
}
}
}
这样,一个简单自己做,又不费时间完成系统激活的程序就完成了。
程序运行效果:
好了,这就是今天的全部内容,希望大家多多关照。