对了,作者的csdn博客在(58条消息) Code_Express的博客_CSDN博客-C#,编程,自定义方法领域博主

废话不多说,上代码


//调用Slmgr.vbs
//所需控件:1个listbox,1个textBox,1个Button
//控件均使用VisualStudio自带原名,否则可能会出现错误
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.Diagnostics;
using System.IO;
 
namespace Windows10_Activation
{
    public partial class Form1 : Form
    {
 
        public 主窗口()
        {
 
            InitializeComponent();
            this.BackColor = Color.White;
            this.Width = 370;
            this.Height = 250;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }
        private string First_Count = "";
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
 
        private void Form1_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))
            {
            listbox1.Add(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;
            }
        }
    }
之后,我们可以看到效果:

本站作者已申明原创,禁止转载!

文章内容属作者个人观点,不代表本站立场,如有侵权立删。

   口袋儿题库-青少儿编程自测题库