[英]is there any c# class which can be use to retrieve total number of hard disk partitions or other information ?
我需要在c#中以编程方式检索HDD相关信息,例如分区总数,安装驱动程序操作系统等等。
You can get available HDD related information from: 您可以从以下位置获取与HDD相关的信息:
http://msdn.microsoft.com/en-us/library/aa394132(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa394132(VS.85).aspx
sample: 样品:
ManagementClass sampleClass= new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection SampleDrive= driveClass.GetInstances();
string Information="";
foreach (ManagementObject drives in SampleDrive)
{
foreach (PropertyData HDDproperty in drives .Properties)
{
Information +="HDDProperty: {0}, HDDValue: {1}", HDDproperty .Name, HDDproperty .Value);
}
}
For most information, you can use the DriveInfo class. 对于大多数信息,您可以使用DriveInfo类。
using System;
using System.IO;
class Info {
public static void Main() {
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
//There are more attributes you can use.
//Check the MSDN link for a complete example.
Console.WriteLine(drive.Name);
if (drive.IsReady) Console.WriteLine(drive.TotalSize);
}
}
}
WMI to rescue WMI救援
You can use WMI queries to fetch information about system. 您可以使用WMI查询来获取有关系统的信息。
Example to fetch OS information related to OS 获取与OS相关的OS信息的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.