Loading
0

c#中读取磁盘分区格式/fat32/ntfs并转换磁盘格式

技术小学生微信公众号
腾讯云服务器大促销。
华为服务器
前言:c#中读取磁盘格式方法,c#检测磁盘是否是ntfs或者fat32格式,c#磁盘转换格式方法

private void Frm_Main_Load(object sender, EventArgs e)
        {
            SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk");//查询磁盘信息
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);//创建WMI查询对象
            foreach (ManagementObject disk in searcher.Get())//遍历所有磁盘
            {
                comboBox1.Items.Add(disk["Name"].ToString());//将磁盘名称添加到下拉列表中
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DriveInfo DInfo = new DriveInfo(comboBox1.Text);//创建驱动器对象
            textBox1.Text = DInfo.DriveFormat;//显示磁盘格式
            if (textBox1.Text == "NTFS")//判断是否为NTFS格式
                button2.Enabled = false;//设置转换按钮不可用
            else if (textBox1.Text == "FAT32")//判断是否为FAT32格式
                button2.Enabled = true;//设置转换按钮可用
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();//创建进程对象
            process.StartInfo.FileName = "cmd.exe";//启动cmd命令
            process.StartInfo.Arguments = "/c convert " + textBox1.Text + " /fs:ntfs";//设置转换命令
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//隐藏窗口
            process.StartInfo.UseShellExecute = false;//是否使用系统外壳程序启动进程
            process.StartInfo.RedirectStandardInput = true;//是否从流中读取
            process.StartInfo.RedirectStandardOutput = true;//是否写入流
            process.StartInfo.RedirectStandardError = true;//是否将错误信息写入流
            process.StartInfo.CreateNoWindow = true;//是否在新窗口中启动进程
            process.Start();//启动进程            
            process.WaitForExit();//执行完退出
        }

技术小学生微信公众号
华为服务器
腾讯云服务器大促销。

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:https://blog.tag.gg/showinfo-23-35945-0.html
亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?
上一篇:c#中图形显示磁盘的使用量及未使用量方法
下一篇:利用c#代码格式化硬盘磁盘方法