如何获得硬盘序列号

本文是我摘抄网上的东西,谢谢



硬盘序列号(Serial Number)不等于卷标号(Volume Name),后者虽然很容易得到,但是 格式化分区后就会重写,不可靠。遗憾的是很多朋友往往分不清这一点。


要得到硬盘的物理序列号,可以通过WMI,也就是Win32_PhysicalMedia.SerialNumber。可惜的是Windows 98/ME的WMI并不支持这个类,访问时会出现异常。


受陆麟的例子的启发,我们还可以通过S.M.A.R.T.接口,直接从RING3调用API DeviceIoControl()来获取硬盘信息,而不需要写VXD或者DRIVER。这样这个问题就解决了,我对它进行了封装,大量使用了 P/Invoke技术,一个完整的Library。支持Windows 98-2003。
使用上很简单:


HardDiskInfo hdd = AtapiDevice.GetHddInfo(0); // 第一个硬盘
Console.WriteLine("Module Number: {0}", hdd.ModuleNumber);
Console.WriteLine("Serial Number: {0}", hdd.SerialNumber);
Console.WriteLine("Firmware: {0}", hdd.Firmware);
Console.WriteLine("Capacity: {0} M", hdd.Capacity);


下面是全部代码:

None.gif
None.gif
using  System;
None.gif
using  System.Runtime.InteropServices;
None.gif
using  System.Text;
None.gif
None.gif
None.gif
namespace  Sunmast.Hardware
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif[Serializable]
InBlock.gif
public struct HardDiskInfo
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// 型号
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic string ModuleNumber;
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// 固件版本
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic string Firmware;
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// 序列号
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic string SerialNumber;
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// 容量,以M为单位
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic uint Capacity;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
Internal Structs#region Internal Structs
InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1)]
InBlock.gif
internal struct GetVersionOutParams
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public byte bVersion;
InBlock.gif
public byte bRevision;
InBlock.gif
public byte bReserved;
InBlock.gif
public byte bIDEDeviceMap;
InBlock.gif
public uint fCapabilities;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=4)]
InBlock.gif
public uint[] dwReserved; // For future use.
ExpandedSubBlockEnd.gif
}

InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1)]
InBlock.gif
internal struct IdeRegs
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public byte bFeaturesReg;
InBlock.gif
public byte bSectorCountReg;
InBlock.gif
public byte bSectorNumberReg;
InBlock.gif
public byte bCylLowReg;
InBlock.gif
public byte bCylHighReg;
InBlock.gif
public byte bDriveHeadReg;
InBlock.gif
public byte bCommandReg;
InBlock.gif
public byte bReserved;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1)]
InBlock.gif
internal struct SendCmdInParams
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public uint cBufferSize;
InBlock.gif
public IdeRegs irDriveRegs;
InBlock.gif
public byte bDriveNumber;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=3)]
InBlock.gif
public byte[] bReserved;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=4)]
InBlock.gif
public uint[] dwReserved;
InBlock.gif
public byte bBuffer;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1)]
InBlock.gif
internal struct DriverStatus
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public byte bDriverError;
InBlock.gif
public byte bIDEStatus;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=2)]
InBlock.gif
public byte[] bReserved;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=2)]
InBlock.gif
public uint[] dwReserved;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1)]
InBlock.gif
internal struct SendCmdOutParams
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public uint cBufferSize;
InBlock.gif
public DriverStatus DriverStatus;
InBlock.gif
public IdSector bBuffer;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential, Pack
=1, Size=512)]
InBlock.gif
internal struct IdSector
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
public ushort wGenConfig;
InBlock.gif
public ushort wNumCyls;
InBlock.gif
public ushort wReserved;
InBlock.gif
public ushort wNumHeads;
InBlock.gif
public ushort wBytesPerTrack;
InBlock.gif
public ushort wBytesPerSector;
InBlock.gif
public ushort wSectorsPerTrack;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=3)]
InBlock.gif
public ushort[] wVendorUnique;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=20)]
InBlock.gif
public byte[] sSerialNumber;
InBlock.gif
public ushort wBufferType;
InBlock.gif
public ushort wBufferSize;
InBlock.gif
public ushort wECCSize;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=8)]
InBlock.gif
public byte[] sFirmwareRev;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=40)]
InBlock.gif
public byte[] sModelNumber;
InBlock.gif
public ushort wMoreVendorUnique;
InBlock.gif
public ushort wDoubleWordIO;
InBlock.gif
public ushort wCapabilities;
InBlock.gif
public ushort wReserved1;
InBlock.gif
public ushort wPIOTiming;
InBlock.gif
public ushort wDMATiming;
InBlock.gif
public ushort wBS;
InBlock.gif
public ushort wNumCurrentCyls;
InBlock.gif
public ushort wNumCurrentHeads;
InBlock.gif
public ushort wNumCurrentSectorsPerTrack;
InBlock.gif
public uint ulCurrentSectorCapacity;
InBlock.gif
public ushort wMultSectorStuff;
InBlock.gif
public uint ulTotalAddressableSectors;
InBlock.gif
public ushort wSingleWordDMA;
InBlock.gif
public ushort wMultiWordDMA;
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=128)]
InBlock.gif
public byte[] bReserved;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif
#endregion

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// ATAPI驱动器相关
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic class AtapiDevice
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
DllImport#region DllImport
InBlock.gif
InBlock.gif
InBlock.gif[DllImport(
"kernel32.dll", SetLastError=true)]
InBlock.gif
static extern int CloseHandle(IntPtr hObject);
InBlock.gif
InBlock.gif
InBlock.gif[DllImport(
"kernel32.dll", SetLastError=true)]
InBlock.gif
static extern IntPtr CreateFile(
InBlock.gif
string lpFileName,
InBlock.gif
uint dwDesiredAccess,
InBlock.gif
uint dwShareMode,
InBlock.gifIntPtr lpSecurityAttributes,
InBlock.gif
uint dwCreationDisposition,
InBlock.gif
uint dwFlagsAndAttributes,
InBlock.gifIntPtr hTemplateFile);
InBlock.gif
InBlock.gif
InBlock.gif[DllImport(
"kernel32.dll")]
InBlock.gif
static extern int DeviceIoControl(
InBlock.gifIntPtr hDevice,
InBlock.gif
uint dwIoControlCode,
InBlock.gifIntPtr lpInBuffer,
InBlock.gif
uint nInBufferSize,
InBlock.gif
ref GetVersionOutParams lpOutBuffer,
InBlock.gif
uint nOutBufferSize,
InBlock.gif
ref uint lpBytesReturned,
InBlock.gif[Out] IntPtr lpOverlapped);
InBlock.gif
InBlock.gif
InBlock.gif[DllImport(
"kernel32.dll")]
InBlock.gif
static extern int DeviceIoControl(
InBlock.gifIntPtr hDevice,
InBlock.gif
uint dwIoControlCode,
InBlock.gif
ref SendCmdInParams lpInBuffer,
InBlock.gif
uint nInBufferSize,
InBlock.gif
ref SendCmdOutParams lpOutBuffer,
InBlock.gif
uint nOutBufferSize,
InBlock.gif
ref uint lpBytesReturned,
InBlock.gif[Out] IntPtr lpOverlapped);
InBlock.gif
InBlock.gif
InBlock.gif
const uint DFP_GET_VERSION = 0x00074080;
InBlock.gif
const uint DFP_SEND_DRIVE_COMMAND = 0x0007c084;
InBlock.gif
const uint DFP_RECEIVE_DRIVE_DATA = 0x0007c088;
InBlock.gif
InBlock.gif
InBlock.gif
const uint GENERIC_READ = 0x80000000;
InBlock.gif
const uint GENERIC_WRITE = 0x40000000;
InBlock.gif
const uint FILE_SHARE_READ = 0x00000001;
InBlock.gif
const uint FILE_SHARE_WRITE = 0x00000002;
InBlock.gif
const uint CREATE_NEW = 1;
InBlock.gif
const uint OPEN_EXISTING = 3;
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif
#endregion

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
GetHddInfo#region GetHddInfo
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// 获得硬盘信息
InBlock.gif
/// </summary>
InBlock.gif
/// <param name="driveIndex">硬盘序号</param>
InBlock.gif
/// <returns>硬盘信息</returns>
InBlock.gif
/// <remarks>
InBlock.gif
/// 参考lu0的文章:http://lu0s1.3322.org/App/2k1103.html
InBlock.gif
/// by sunmast for everyone
InBlock.gif
/// thanks lu0 for his great works
InBlock.gif
/// 在Windows 98/ME中,S.M.A.R.T并不缺省安装,请将SMARTVSD.VXD拷贝到%SYSTEM%\IOSUBSYS目录下。
InBlock.gif
/// 在Windows 2000/2003下,需要Administrators组的权限。
InBlock.gif
/// </remarks>
InBlock.gif
/// <example>
InBlock.gif
/// AtapiDevice.GetHddInfo()
ExpandedSubBlockEnd.gif
/// </example>

InBlock.gifpublic static HardDiskInfo GetHddInfo(byte driveIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
switch(Environment.OSVersion.Platform)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
case PlatformID.Win32Windows:
InBlock.gif
return GetHddInfo9x(driveIndex);
InBlock.gif
case PlatformID.Win32NT:
InBlock.gif
return GetHddInfoNT(driveIndex);
InBlock.gif
case PlatformID.Win32S:
InBlock.gif
throw new NotSupportedException("Win32s is not supported.");
InBlock.gif
case PlatformID.WinCE:
InBlock.gif
throw new NotSupportedException("WinCE is not supported.");
InBlock.gif
default:
InBlock.gif
throw new NotSupportedException("Unknown Platform.");
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
GetHddInfo9x#region GetHddInfo9x
InBlock.gif
InBlock.gif
InBlock.gif
private static HardDiskInfo GetHddInfo9x(byte driveIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifGetVersionOutParams vers 
= new GetVersionOutParams();
InBlock.gifSendCmdInParams inParam 
= new SendCmdInParams();
InBlock.gifSendCmdOutParams outParam 
= new SendCmdOutParams();
InBlock.gif
uint bytesReturned = 0;
InBlock.gif
InBlock.gif
InBlock.gifIntPtr hDevice 
= CreateFile(
InBlock.gif
@"\\.\Smartvsd",
InBlock.gif
0,
InBlock.gif
0,
InBlock.gifIntPtr.Zero,
InBlock.gifCREATE_NEW,
InBlock.gif
0,
InBlock.gifIntPtr.Zero);
InBlock.gif
if (hDevice == IntPtr.Zero)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
throw new Exception("Open smartvsd.vxd failed.");
ExpandedSubBlockEnd.gif}

InBlock.gif
if (0 == DeviceIoControl(
InBlock.gifhDevice,
InBlock.gifDFP_GET_VERSION,
InBlock.gifIntPtr.Zero,
InBlock.gif
0,
InBlock.gif
ref vers,
InBlock.gif(
uint)Marshal.SizeOf(vers),
InBlock.gif
ref bytesReturned,
InBlock.gifIntPtr.Zero))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception("DeviceIoControl failed:DFP_GET_VERSION");
ExpandedSubBlockEnd.gif}

InBlock.gif
// If IDE identify command not supported, fails
InBlock.gif
if (0 == (vers.fCapabilities & 1))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception("Error: IDE identify command not supported.");
ExpandedSubBlockEnd.gif}

InBlock.gif
if (0 != (driveIndex & 1))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bDriveHeadReg 
= 0xb0;
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bDriveHeadReg 
= 0xa0;
ExpandedSubBlockEnd.gif}

InBlock.gif
if (0 != (vers.fCapabilities & (16 >> driveIndex)))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
// We don''t detect a ATAPI device.
InBlock.gif
CloseHandle(hDevice);
InBlock.gif
throw new Exception(string.Format("Drive {0} is a ATAPI device, we don''t detect it",driveIndex + 1));
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bCommandReg 
= 0xec;
ExpandedSubBlockEnd.gif}

InBlock.gifinParam.bDriveNumber 
= driveIndex;
InBlock.gifinParam.irDriveRegs.bSectorCountReg 
= 1;
InBlock.gifinParam.irDriveRegs.bSectorNumberReg 
= 1;
InBlock.gifinParam.cBufferSize 
= 512;
InBlock.gif
if (0 == DeviceIoControl(
InBlock.gifhDevice,
InBlock.gifDFP_RECEIVE_DRIVE_DATA,
InBlock.gif
ref inParam,
InBlock.gif(
uint)Marshal.SizeOf(inParam),
InBlock.gif
ref outParam,
InBlock.gif(
uint)Marshal.SizeOf(outParam),
InBlock.gif
ref bytesReturned,
InBlock.gifIntPtr.Zero))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
ExpandedSubBlockEnd.gif}

InBlock.gifCloseHandle(hDevice);
InBlock.gif
InBlock.gif
InBlock.gif
return GetHardDiskInfo(outParam.bBuffer);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif
#endregion

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
GetHddInfoNT#region GetHddInfoNT
InBlock.gif
InBlock.gif
InBlock.gif
private static HardDiskInfo GetHddInfoNT(byte driveIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifGetVersionOutParams vers 
= new GetVersionOutParams();
InBlock.gifSendCmdInParams inParam 
= new SendCmdInParams();
InBlock.gifSendCmdOutParams outParam 
= new SendCmdOutParams();
InBlock.gif
uint bytesReturned = 0;
InBlock.gif
InBlock.gif
InBlock.gif
// We start in NT/Win2000
InBlock.gif
IntPtr hDevice = CreateFile(
InBlock.gif
string.Format(@"\\.\PhysicalDrive{0}",driveIndex),
InBlock.gifGENERIC_READ 
| GENERIC_WRITE,
InBlock.gifFILE_SHARE_READ 
| FILE_SHARE_WRITE,
InBlock.gifIntPtr.Zero,
InBlock.gifOPEN_EXISTING,
InBlock.gif
0,
InBlock.gifIntPtr.Zero);
InBlock.gif
if (hDevice == IntPtr.Zero)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
throw new Exception("CreateFile faild.");
ExpandedSubBlockEnd.gif}

InBlock.gif
if (0 == DeviceIoControl(
InBlock.gifhDevice,
InBlock.gifDFP_GET_VERSION,
InBlock.gifIntPtr.Zero,
InBlock.gif
0,
InBlock.gif
ref vers,
InBlock.gif(
uint)Marshal.SizeOf(vers),
InBlock.gif
ref bytesReturned,
InBlock.gifIntPtr.Zero))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception(string.Format("Drive {0} may not exists.",driveIndex + 1));
ExpandedSubBlockEnd.gif}

InBlock.gif
// If IDE identify command not supported, fails
InBlock.gif
if (0 == (vers.fCapabilities & 1))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception("Error: IDE identify command not supported.");
ExpandedSubBlockEnd.gif}

InBlock.gif
// Identify the IDE drives
InBlock.gif
if (0 != (driveIndex & 1))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bDriveHeadReg 
= 0xb0;
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bDriveHeadReg
=0xa0;
ExpandedSubBlockEnd.gif}

InBlock.gif
if (0 != (vers.fCapabilities & (16 >> driveIndex)))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
// We don''t detect a ATAPI device.
InBlock.gif
CloseHandle(hDevice);
InBlock.gif
throw new Exception(string.Format("Drive {0} is a ATAPI device, we don''t detect it.",driveIndex + 1));
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifinParam.irDriveRegs.bCommandReg 
= 0xec;
ExpandedSubBlockEnd.gif}

InBlock.gifinParam.bDriveNumber 
= driveIndex;
InBlock.gifinParam.irDriveRegs.bSectorCountReg 
= 1;
InBlock.gifinParam.irDriveRegs.bSectorNumberReg 
= 1;
InBlock.gifinParam.cBufferSize 
= 512;
InBlock.gif
InBlock.gif
InBlock.gif
if (0 == DeviceIoControl(
InBlock.gifhDevice,
InBlock.gifDFP_RECEIVE_DRIVE_DATA,
InBlock.gif
ref inParam,
InBlock.gif(
uint)Marshal.SizeOf(inParam),
InBlock.gif
ref outParam,
InBlock.gif(
uint)Marshal.SizeOf(outParam),
InBlock.gif
ref bytesReturned,
InBlock.gifIntPtr.Zero))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCloseHandle(hDevice);
InBlock.gif
throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
ExpandedSubBlockEnd.gif}

InBlock.gifCloseHandle(hDevice);
InBlock.gif
InBlock.gif
InBlock.gif
return GetHardDiskInfo(outParam.bBuffer);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif
#endregion

InBlock.gif
InBlock.gif
InBlock.gif
private static HardDiskInfo GetHardDiskInfo(IdSector phdinfo)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifHardDiskInfo hddInfo 
= new HardDiskInfo();
InBlock.gif
InBlock.gif
InBlock.gifChangeByteOrder(phdinfo.sModelNumber);
InBlock.gifhddInfo.ModuleNumber 
= Encoding.ASCII.GetString(phdinfo.sModelNumber).Trim();
InBlock.gif
InBlock.gif
InBlock.gifChangeByteOrder(phdinfo.sFirmwareRev);
InBlock.gifhddInfo.Firmware 
= Encoding.ASCII.GetString(phdinfo.sFirmwareRev).Trim();
InBlock.gif
InBlock.gif
InBlock.gifChangeByteOrder(phdinfo.sSerialNumber);
InBlock.gifhddInfo.SerialNumber 
= Encoding.ASCII.GetString(phdinfo.sSerialNumber).Trim();
InBlock.gif
InBlock.gif
InBlock.gifhddInfo.Capacity 
= phdinfo.ulTotalAddressableSectors / 2 / 1024;
InBlock.gif
InBlock.gif
InBlock.gif
return hddInfo;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
private static void ChangeByteOrder(byte[] charArray)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
byte temp;
InBlock.gif
for(int i = 0; i < charArray.Length; i += 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.giftemp 
= charArray;
InBlock.gifcharArray 
= charArray[i+1];
InBlock.gifcharArray[i
+1= temp;
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif
#endregion

ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif



注:


在Windows 98/ME中,S.M.A.R.T并不缺省安装,请将SMARTVSD.VXD拷贝到%SYSTEM%\IOSUBSYS目录下。
在Windows 2000/2003下,需要Administrators组的权限。
不要在装有SCSI硬盘的机器上尝试了,因为SCSI硬盘根本不存在序列号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值