用”SMARTVSD.VXD“技术获得硬盘出厂序列号可靠吗?(10分)

  • 主题发起人 主题发起人 zhoufujin
  • 开始时间 开始时间
Z

zhoufujin

Unregistered / Unconfirmed
GUEST, unregistred user!
用”SMARTVSD.VXD“技术获得硬盘出厂序列号可靠吗?
请发表见解
1、98,2000,XP下通用吗?
2、受其他限制吗?
 
vxd技术在win2000及以上已经不再使用了。
搜一下论坛,有很多源代码。
我试过别人的代码,基本上不同系统不同实现方法。
应该没什么限制,我试了大概10台机子左右。
 
既然"vxd技术在win2000及以上已经不再使用了。",那么
可以说使用该技术获得硬盘出厂序列号“在win2000及以上”将
得不到技术支持,进一步说明这种方法不可靠或不推荐的,
那么有什么方法解决这个问题?
 
接受答案了.
 
你可以到这个网站看看:http://www.tommstudio.com, 搜索一下序列号.
下面贴出我下的一个例子,该例子在win9x/2k/xp下测试过,都能取出硬盘
序列号,不过9x下要拷贝一下文件,里面有叙述.
DPR 文件:
==============================================================================
program gethardwarep;
uses
Forms,
gethardware in 'gethardware.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
==============================================================================
DFM File:
==============================================================================
object Form1: TForm1
Left = 197
Top = 115
Width = 501
Height = 226
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 68
Width = 58
Height = 23
Caption = 'Label1'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -20
Font.Name = 'Times New Roman'
Font.Style = [fsBold]
ParentFont = False
end
object Label2: TLabel
Left = 16
Top = 96
Width = 58
Height = 23
Caption = 'Label2'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -20
Font.Name = 'Times New Roman'
Font.Style = [fsBold]
ParentFont = False
end
object Label3: TLabel
Left = 72
Top = 5
Width = 348
Height = 52
Alignment = taCenter
Caption = 'For more informaition,please visit http://www.tommstudio.com'
Font.Charset = ANSI_CHARSET
Font.Color = clRed
Font.Height = -24
Font.Name = 'Times New Roman'
Font.Style = [fsBold]
ParentFont = False
WordWrap = True
end
object Label4: TLabel
Left = 16
Top = 124
Width = 58
Height = 23
Caption = 'Label4'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -20
Font.Name = 'Times New Roman'
Font.Style = [fsBold]
ParentFont = False
end
object Button1: TButton
Left = 192
Top = 149
Width = 121
Height = 33
Caption = 'GetHardInfo'
TabOrder = 0
OnClick = Button1Click
end
end
==============================================================================
PAS File:
==============================================================================
{
********GetHardWare Information***************
http://www.tommstudio.com
Author:tommstudio
}
unit gethardware;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function GetDisplayFrequency: Integer;
function GetIdeSerialNumber: pchar;
function GetCPUSpeed:do
uble;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption := 'Current DisplayFrequency: (' + inttostr(GetDisplayFrequency) + ') Hz';
label2.Caption := 'HardDriver SerialNumber: (' + strpas(GetIdeSerialNumber) + ')';
label4.caption := 'Current CPU Speed: (' + floattostr(GetCPUSpeed) + ') MHz';
end;

function GetDisplayFrequency: Integer;
var
DeviceMode: TDeviceMode;
// 这个函数返回的显示刷新率是以Hz为单位的
begin
EnumDisplaySettings(nil, Cardinal(-1), DeviceMode);
Result := DeviceMode.dmDisplayFrequency;
end;

//获取第一个IDE硬盘的序列号
function GetIdeSerialNumber: pchar;
const IDENTIFY_BUFFER_SIZE = 512;
type
TIDERegs = packed record
bFeaturesReg: BYTE;
// Used for specifying SMART "commands".
bSectorCountReg: BYTE;
// IDE sector count register
bSectorNumberReg: BYTE;
// IDE sector number register
bCylLowReg: BYTE;
// IDE low order cylinder value
bCylHighReg: BYTE;
// IDE high order cylinder value
bDriveHeadReg: BYTE;
// IDE drive/head register
bCommandReg: BYTE;
// Actual IDE command.
bReserved: BYTE;
// reserved for future use. Must be zero.
end;
TSendCmdInParams = packed record
// Buffer size in bytes
cBufferSize: DWORD;
// Structure with drive register values.
irDriveRegs: TIDERegs;
// Physical drive number to send command to (0,1,2,3).
bDriveNumber: BYTE;
bReserved: array[0..2] of Byte;
dwReserved: array[0..3] of DWORD;
bBuffer: array[0..0] of Byte;
// Input buffer.
end;
TIdSector = packed record
wGenConfig: Word;
wNumCyls: Word;
wReserved: Word;
wNumHeads: Word;
wBytesPerTrack: Word;
wBytesPerSector: Word;
wSectorsPerTrack: Word;
wVendorUnique: array[0..2] of Word;
sSerialNumber: array[0..19] of CHAR;
wBufferType: Word;
wBufferSize: Word;
wECCSize: Word;
sFirmwareRev: array[0..7] of Char;
sModelNumber: array[0..39] of Char;
wMoreVendorUnique: Word;
wDoubleWordIO: Word;
wCapabilities: Word;
wReserved1: Word;
wPIOTiming: Word;
wDMATiming: Word;
wBS: Word;
wNumCurrentCyls: Word;
wNumCurrentHeads: Word;
wNumCurrentSectorsPerTrack: Word;
ulCurrentSectorCapacity: DWORD;
wMultSectorStuff: Word;
ulTotalAddressableSectors: DWORD;
wSingleWordDMA: Word;
wMultiWordDMA: Word;
bReserved: array[0..127] of BYTE;
end;
PIdSector = ^TIdSector;
TDriverStatus = packed record
// 驱动器返回的错误代码,无错则返回0
bDriverError: Byte;
// IDE出错寄存器的内容,只有当bDriverError 为 SMART_IDE_ERROR 时有效
bIDEStatus: Byte;
bReserved: array[0..1] of Byte;
dwReserved: array[0..1] of DWORD;
end;
TSendCmdOutParams = packed record
// bBuffer的大小
cBufferSize: DWORD;
// 驱动器状态
DriverStatus: TDriverStatus;
// 用于保存从驱动器读出的数据的缓冲区,实际长度由cBufferSize决定
bBuffer: array[0..0] of BYTE;
end;
var hDevice: THandle;
cbBytesReturned: DWORD;
ptr: PChar;
SCIP: TSendCmdInParams;
aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
procedure ChangeByteOrder(var Data;
Size: Integer);
var ptr: PChar;
i: Integer;
c: Char;
begin
ptr := @Data;
for i := 0 to (Size shr 1) - 1do
begin
c := ptr^;
ptr^ := (ptr + 1)^;
(ptr + 1)^ := c;
Inc(ptr, 2);
end;
end;
begin
Result := '';
// 如果出错则返回空串
if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then
begin
// Windows NT, Windows 2000
// 提示! 改变名称可适用于其它驱动器,如第二个驱动器: '//./PhysicalDrive1/'
hDevice := CreateFile('//./PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
end else
// Version Windows 95 OSR2, Windows 98
hDevice := CreateFile('//./SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
Exit;
try
FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
cbBytesReturned := 0;
// Set up data structures for IDENTIFY command.
with SCIPdo
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
// bDriveNumber := 0;
with irDriveRegsdo
begin
bSectorCountReg := 1;
bSectorNumberReg := 1;
// if Win32Platform=VER_PLATFORM_WIN32_NT then
bDriveHeadReg := $A0
// else
bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4);
bDriveHeadReg := $A0;
bCommandReg := $EC;
end;
end;
if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then
Exit;
finally
CloseHandle(hDevice);
end;
with PIdSector(@IdOutCmd.bBuffer)^do
begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
(PChar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;
Result := PChar(@sSerialNumber);
end;
end;

// 更多关于 S.M.A.R.T. ioctl 的信息可查看:
// http://www.microsoft.com/hwdev/download/respec/iocltapi.rtf
// MSDN库中也有一些简单的例子
// Windows Development -> Win32 Device Driver Kit ->
// SAMPLE: SmartApp.exe Accesses SMART stats in IDE drives
// 还可以查看 http://www.mtgroup.ru/~alexk
// IdeInfo.zip - 一个简单的使用了S.M.A.R.T. Ioctl API的Delphi应用程序
// 注意:
// WinNT/Win2000 - 你必须拥有对硬盘的读/写访问权限
// Win98
// SMARTVSD.VXD 必须安装到 /windows/system/iosubsys
// (不要忘记在复制后重新启动系统)

function GetCPUSpeed:do
uble;
const
DelayTime = 500;
// 时间单位是毫秒
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;

SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
end;

end.

 
后退
顶部