实现效果:
知识运用:
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); }
- }
恢复注册表
来源: http://www.bubuko.com/infodetail-2935907.html