如何获得在PC中的所有驱动器。和每个类型的每个驱动器和自由空间的
how to get all drives in a PC. and types of every drive and free-space of each
即。系统驱动器,CD驱动器,DVD驱动器,可移动,...等。
i.e. System-Drive, CD-Drive, DVD-Drive, Removable, ... etc.
如果系统上安装有一个新的驱动器笔式驱动器或外部硬盘
If a system is attached with a new drive may be a pen drive or external hard disc.
如何探测到它们在附件?时间
要获得驱动器的列表,你可以使用的 System.IO.DriveInfo 类:
To get a list of the drives, you can use the System.IO.DriveInfo class:
foreach(var drive in DriveInfo.GetDrives())
{
Console.WriteLine("Drive Type: {0}", drive.DriveType);
Console.WriteLine("Drive Size: {0}", drive.TotalSize);
Console.WriteLine("Drive Free Space: {0}", drive.TotalFreeSpace);
}
不幸的是,这并不提供一种方式来监听USB钥匙的插入。还有另外一个问题处理,你可以看看:
Unfortunately, this doesn't provide a way to listen for USB Key Insertions. There is another question dealing with that you could check out:
.NET - 检测USB驱动器插入和移除...
上一篇:读取性能计数器从C#:实例没有在指定的类别中存在计数器、实例、性能、类别
下一篇:为Windows编写跨平台(32位和64位兼容的)程序(如值为anycpu在.NET)值为、程序、平台、Windows