2012年2月28日星期二

Windows7密钥证书安装工具

using System;using System.Diagnostics;using System.IO;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Windows7密钥证书安装工具{    public partial class Form1 : Form    {        string filePath;        string fileNmae;        public Form1()        {            InitializeComponent();        }        private void btnChoiceCert_Click(object sender, EventArgs e)        {            openFileDialog1.ShowReadOnly = true;            openFileDialog1.RestoreDirectory = true;            openFileDialog1.Filter = "许可证文件(*.xrm-ms)|*.xrm-ms|所有文件|*.*";            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);            openFileDialog1.ShowDialog();            filePath = openFileDialog1.FileName;            fileNmae = Path.GetFileName(filePath);            txtCert.Text = filePath;                    }        private void btnAddCert_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName="cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            if (txtCert.Text=="")            {                MessageBox.Show("输入有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);                return;            }             else            {                p.StandardInput.WriteLine("slmgr -ilc " + filePath);            }        }        private void btnAddKey_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            if (txtKey.TextLength!=29)            {                MessageBox.Show("输入有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);                return;            }            else                p.StandardInput.WriteLine("slmgr -ipk " + txtKey.Text);        }        private void Form1_Load(object sender, EventArgs e)        {        }        private void btnCerMsg_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            p.StandardInput.WriteLine("slmgr -dlv");        }        private void btnCerStatue_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            p.StandardInput.WriteLine("slmgr -xpr");        }        private void btnClearnKey_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            p.StandardInput.WriteLine("slmgr -cpky");        }        private void btnReam_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            p.StandardInput.WriteLine("slmgr -rearm");        }        private void btnUnstalKey_Click(object sender, EventArgs e)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.AutoFlush = true;            p.StandardInput.WriteLine("slmgr -upk");        }        private void btnAbout_Click(object sender, EventArgs e)        {            AboutBox1 about = new AboutBox1();            about.ShowDialog();        }    }}

Windows7密钥证书安装工具

TAG: