修改磁盘格式

实现效果:

  

知识运用:

  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();                                                //执行完退出
        }

  

猜你喜欢

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