恢复注册表

实现效果:

  

知识运用:

  Process类的StartInfo  StandardInput属性及Start方法

实现代码:

        public Form2()
        {
            InitializeComponent();
            button1.Click-=new EventHandler(button1_Click);     //取消父类的单击事件
            button2.Click -= new EventHandler(button2_Click);   //取消父类的单机事件
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "*.reg|*.reg";
            if (open.ShowDialog() == DialogResult.OK)
                textBox1.Text = open.FileName;
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            try
            {
                Process myProcess = new Process();
                myProcess.StartInfo.FileName = "cmd.exe";
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.StartInfo.RedirectStandardError = true;
                myProcess.StartInfo.RedirectStandardInput = true;
                myProcess.StartInfo.RedirectStandardOutput = true;
                myProcess.Start();
                myProcess.StandardInput.WriteLine("regedit /s " + textBox1.Text);
                MessageBox.Show("注册表恢复成功");
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10326778.html
今日推荐