加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

备份注册表

发布时间:2020-12-14 02:35:26 所属栏目:Windows 来源:网络整理
导读:实现效果: 知识运用: Process类的StartInfo属性 // 获取或设置要传递给当前进程的Start方法的属性 public ProcessStartInfo StartInfo { get; set; } Process类的StandardInput属性 // 只读属性 ?获取拥有写入应用程序输入的流 public StreamWrite StandardI

实现效果:

  

知识运用:

  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); }
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读