备份注册表

实现效果:

  

知识运用:

  Process类的StartInfo属性    //获取或设置要传递给当前进程的Start方法的属性

  public ProcessStartInfo StartInfo { get; set; }

  Process类的StandardInput属性  //只读属性  获取拥有写入应用程序输入的流

  public StreamWrite StandardInput { get; set; }

  Process类的Start方法    //启动当前进程资源

  public bool Start()      //返回进程是否启动成功

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            save.FileName = "Backup";
            save.Filter = "*.reg|*.reg";
            save.ShowDialog();
            textBox1.Text = save.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                Process ps = new Process();
                ps.StartInfo.FileName = "cmd.exe";
                ps.StartInfo.CreateNoWindow = true;         //设置启动该进程而不创建包含它的新窗口
                ps.StartInfo.UseShellExecute = false;       //设置直接从可执行文件创建进程
                ps.StartInfo.RedirectStandardInput = true;
                ps.StartInfo.RedirectStandardOutput = true;
                ps.StartInfo.RedirectStandardError = true;
                ps.Start();
                ps.StandardInput.WriteLine("regedit /e "+textBox1.Text);
                MessageBox.Show("注册表已备份成功!");
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10326341.html