获得每一个独立硬盘下的分区卷标 如题:我的机器上有两个硬盘,一个有4个分区另一个有两个,如何能够做到分别获得每一个硬盘下的卷标信息? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SelectQuery query = new SelectQuery("Select * From Win32_LogicalDisk"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); string str = ""; foreach (ManagementBaseObject disk in searcher.Get()) { str += "\r\n" + disk["Name"] + " " + disk["DriveType"] + " " + disk["VolumeName"]; } MessageBox.Show(str);using System.Management;项目——添加引用——System.Management——确定 namespace System.IO{ public enum DriveType { // 摘要: // 驱动器类型未知。 Unknown = 0, // // 摘要: // 此驱动器没有根目录。 NoRootDirectory = 1, // // 摘要: // 此驱动器是一个可移动存储设备,如软盘驱动器或 USB 闪存驱动器。 Removable = 2, // // 摘要: // 此驱动器是一个固定磁盘。 Fixed = 3, // // 摘要: // 此驱动器是一个网络驱动器。 Network = 4, // // 摘要: // 此驱动器是一个光盘设备,如 CD 或 DVD-ROM。 CDRom = 5, // // 摘要: // 此驱动器是一个 RAM 磁盘。 Ram = 6, }}DiskType为System.IO命名空间下的系统定义的枚举类型,只需要判断下DiskType类型为3,即为硬盘 二楼的方法我试过,这种情况下显示出来的还是所有的硬盘分区。我想得到的是,当选择disk 0 时,只显示disk 0上的分区,选disk1时,只显示disk1上的分区。而且无论是使用Win32_LogicalDisk 还是DriveInfo.GetDrives(),他们都是按照分区的字母顺序来排的,就是:C,D,E......这样。而我的disk0上的分区是H和M,disk1上才是C和D。因此,有什么办法能够按照硬盘的顺序来显示分区。就是:disk0:H,Mdisk1:C,D,E,F这样来显示 namespace FileCHecker{ public partial class CheckerOptions : DevExpress.XtraEditors.XtraForm { public CheckerOptions() { InitializeComponent(); //设定用户可以更改窗口的边框属性 SkinManager.EnableFormSkins(); //设定窗口边框属性为黑色,如果不使用下面的代码,窗口边框将使用默认设置 mainFormLookAndFeel.LookAndFeel.SkinName = "Black"; SetCheckOptions(); } private void SetCheckOptions() { FileInfo configXMLFile = new FileInfo("Config.xml"); //配置文件不存在 if (!configXMLFile.Exists) { //只检查主文件夹选项选中 this.radBtnOnlyMain.Checked = true; //不选择文件夹名检查选项 this.chkBoxEnableFolderName.Checked = false; this.radBtnFolderWiName.Enabled = false; this.txtEditFolderWiName.Enabled = false; this.radBtnFolderWioName.Enabled = false; this.txtEditFolderWioName.Enabled = false; //不选择文件扩展名选项 this.chkBoxEnableExtName.Checked = false; this.radBtnWiFileExt.Enabled = false; this.txtEditFileWiSpecExt.Enabled = false; this.radBtnWioFileExt.Enabled = false; this.txtEditFileWioSpecExt.Enabled = false; //不选择文件名检查选项 this.chkBoxEnableSpecFileName.Checked = false; this.radBtnWiFileName.Enabled = false; this.txtEditFileWiSpecName.Enabled = false; this.radBtnWioFileName.Enabled = false; this.txtEditFileWioSpecName.Enabled = false; } else { } } //Folder 选项checkbox private void chkBoxEnableFolderName_CheckedChanged(object sender, EventArgs e) { if (this.chkBoxEnableFolderName.Checked) { this.radBtnFolderWiName.Enabled = true; this.radBtnFolderWioName.Enabled = true; } else { this.radBtnFolderWiName.Enabled = false; this.radBtnFolderWioName.Enabled = false; this.txtEditFolderWiName.Enabled = false; this.txtEditFolderWioName.Enabled = false; } } //Folder 选项radioButton private void radBtnFolderWiName_CheckedChanged(object sender, EventArgs e) { if (this.radBtnFolderWiName.Checked) { this.txtEditFolderWiName.Enabled = true; } else { this.txtEditFolderWiName.Enabled = false; } } private void radBtnFolderWioName_CheckedChanged(object sender, EventArgs e) { if (this.radBtnFolderWioName.Checked) { this.txtEditFolderWioName.Enabled = true; } else { this.txtEditFolderWioName.Enabled = false; } } private void chkBoxEnableExtName_CheckedChanged(object sender, EventArgs e) { if (this.chkBoxEnableExtName.Checked) { this.radBtnWiFileExt.Enabled = true; this.radBtnWioFileExt.Enabled = true; } else { this.radBtnWiFileExt.Enabled = false; this.radBtnWioFileExt.Enabled = false; this.txtEditFileWiSpecExt.Enabled = false; this.txtEditFileWioSpecExt.Enabled = false; } } }} 页面按钮的显示无法控制,怎么办? 如何利用递归算法,做权限设计(C#语言版的源代码) Winform的文件上传下载,如何做呢? 远程互联网上实现 部署问题 关于发布服务的一个初级问题 c#怎么操作数据库可写性 用C#获取网络时间的问题 50求一个简单的web页问题大家快来呀 Access中建好的带参数的查询在VS2010中显示为函数,应该怎么调用啊?用的OLEDB,c# Clipboard.ContainsData()与 cdata.GetDataPresent()两个函数的区别是什么? 关于封装的疑问 C# 控件中的图片显示问题请教
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
string str = "";
foreach (ManagementBaseObject disk in searcher.Get())
{
str += "\r\n" + disk["Name"] + " " + disk["DriveType"] + " " + disk["VolumeName"];
}
MessageBox.Show(str);using System.Management;
项目——添加引用——System.Management——确定
namespace System.IO
{
public enum DriveType
{
// 摘要:
// 驱动器类型未知。
Unknown = 0,
//
// 摘要:
// 此驱动器没有根目录。
NoRootDirectory = 1,
//
// 摘要:
// 此驱动器是一个可移动存储设备,如软盘驱动器或 USB 闪存驱动器。
Removable = 2,
//
// 摘要:
// 此驱动器是一个固定磁盘。
Fixed = 3,
//
// 摘要:
// 此驱动器是一个网络驱动器。
Network = 4,
//
// 摘要:
// 此驱动器是一个光盘设备,如 CD 或 DVD-ROM。
CDRom = 5,
//
// 摘要:
// 此驱动器是一个 RAM 磁盘。
Ram = 6,
}
}DiskType为System.IO命名空间下的系统定义的枚举类型,
只需要判断下DiskType类型为3,即为硬盘
我想得到的是,当选择disk 0 时,只显示disk 0上的分区,选disk1时,只显示disk1上的分区。
而且无论是使用Win32_LogicalDisk 还是DriveInfo.GetDrives(),他们都是按照分区的字母顺序来排的,就是:C,D,E......这样。而我的disk0上的分区是H和M,disk1上才是C和D。因此,有什么办法能够按照硬盘的顺序来显示分区。就是:
disk0:H,M
disk1:C,D,E,F
这样来显示
{
public partial class CheckerOptions : DevExpress.XtraEditors.XtraForm
{
public CheckerOptions()
{
InitializeComponent(); //设定用户可以更改窗口的边框属性
SkinManager.EnableFormSkins();
//设定窗口边框属性为黑色,如果不使用下面的代码,窗口边框将使用默认设置
mainFormLookAndFeel.LookAndFeel.SkinName = "Black"; SetCheckOptions();
} private void SetCheckOptions()
{
FileInfo configXMLFile = new FileInfo("Config.xml"); //配置文件不存在
if (!configXMLFile.Exists)
{
//只检查主文件夹选项选中
this.radBtnOnlyMain.Checked = true; //不选择文件夹名检查选项
this.chkBoxEnableFolderName.Checked = false;
this.radBtnFolderWiName.Enabled = false;
this.txtEditFolderWiName.Enabled = false;
this.radBtnFolderWioName.Enabled = false;
this.txtEditFolderWioName.Enabled = false; //不选择文件扩展名选项
this.chkBoxEnableExtName.Checked = false;
this.radBtnWiFileExt.Enabled = false;
this.txtEditFileWiSpecExt.Enabled = false;
this.radBtnWioFileExt.Enabled = false;
this.txtEditFileWioSpecExt.Enabled = false; //不选择文件名检查选项
this.chkBoxEnableSpecFileName.Checked = false;
this.radBtnWiFileName.Enabled = false;
this.txtEditFileWiSpecName.Enabled = false;
this.radBtnWioFileName.Enabled = false;
this.txtEditFileWioSpecName.Enabled = false;
}
else
{ }
} //Folder 选项checkbox
private void chkBoxEnableFolderName_CheckedChanged(object sender, EventArgs e)
{
if (this.chkBoxEnableFolderName.Checked)
{
this.radBtnFolderWiName.Enabled = true;
this.radBtnFolderWioName.Enabled = true;
}
else
{
this.radBtnFolderWiName.Enabled = false;
this.radBtnFolderWioName.Enabled = false;
this.txtEditFolderWiName.Enabled = false;
this.txtEditFolderWioName.Enabled = false;
}
} //Folder 选项radioButton
private void radBtnFolderWiName_CheckedChanged(object sender, EventArgs e)
{
if (this.radBtnFolderWiName.Checked)
{
this.txtEditFolderWiName.Enabled = true;
}
else
{
this.txtEditFolderWiName.Enabled = false;
}
} private void radBtnFolderWioName_CheckedChanged(object sender, EventArgs e)
{
if (this.radBtnFolderWioName.Checked)
{
this.txtEditFolderWioName.Enabled = true;
}
else
{
this.txtEditFolderWioName.Enabled = false;
}
} private void chkBoxEnableExtName_CheckedChanged(object sender, EventArgs e)
{
if (this.chkBoxEnableExtName.Checked)
{
this.radBtnWiFileExt.Enabled = true;
this.radBtnWioFileExt.Enabled = true;
}
else
{
this.radBtnWiFileExt.Enabled = false;
this.radBtnWioFileExt.Enabled = false;
this.txtEditFileWiSpecExt.Enabled = false;
this.txtEditFileWioSpecExt.Enabled = false;
}
}
}
}