修改磁盘格式

Posted on 2019-01-22 20:07  努力成长静待花开  阅读(342)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Dos命令: "/c convert 盘符 /fs:ntfs"

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            DriveInfo Dinfo = new DriveInfo(comboBox1.Text);
            textBox1.Text = Dinfo.DriveFormat;
            if (textBox1.Text == "NTFS")
                button2.Enabled = false;
            else if (textBox1.Text == "FAT32")
                button2.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.Arguments = "/c convert "+textBox1.Text+" /fs:ntfs";
            myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;    //隐藏窗口
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            myProcess.WaitForExit();                                                //执行完退出
        }