DllImport("kernel32.dll")] private static extern int GetVolumeInformation( string lpRootPathName, string lpVolumeNameBuffer, int nVolumeNameSize, ref int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags, string lpFileSystemNameBuffer, int nFileSystemNameSize ); 试一下
using System.Management;ManagementClass mntclass = new ManagementClass("WIN32_DiskDrive"); ManagementObjectCollection mocol = mntclass.GetInstances(); foreach (ManagementObject mo in mocol) { if ("WIN32_NetworkAdapterConfiguration".Equals("WIN32_DiskDrive") && (!(bool)mo["IPEnabled"])) return null; return mo["signature"].ToString(); // or return mo["Model"].ToString(); }
private static extern int GetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);
试一下
http://www.xmlasp.net/n1227c13.aspx
ManagementObjectCollection mocol = mntclass.GetInstances();
foreach (ManagementObject mo in mocol)
{
if ("WIN32_NetworkAdapterConfiguration".Equals("WIN32_DiskDrive")
&& (!(bool)mo["IPEnabled"])) return null; return mo["signature"].ToString();
// or return mo["Model"].ToString();
}
{ string hardDiskID = null;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
if (hardDiskID == null)
{
hardDiskID = mo.Properties["Model"].Value.ToString();
}
else
{
hardDiskID += ";" + mo.Properties["Model"].Value.ToString();
}
}
return (hardDiskID == null) ? "None" : hardDiskID; }
/// 获取硬盘ID
/// </summary>
/// <returns> string </returns>
public static string GetHDid()
{
string HDid = " ";
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
}
return HDid.ToString();
}