如何使用C#来获得个人电脑的所有驱动器与.NET [英] How to get all drives in PC with .NET using C#

查看:143
本文介绍了如何使用C#来获得个人电脑的所有驱动器与.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得在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:

<一个href="http://stackoverflow.com/questions/620144/detecting-usb-drive-insertion-and-removal-using-windows-service-and-c">.NET - 检测USB驱动器插入和移除...

这篇关于如何使用C#来获得个人电脑的所有驱动器与.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆