Typhon获取硬盘和硬盘序列号
此代码为 CodeOcean 里的代码
unit PhysicalMediaInfomw;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, DAV_ProcessorInfoComponent, Forms, Controls,
Graphics, Dialogs, StdCtrls, variants, windows, ActiveX, stdole2, comobj;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ProcessorInfoComponent1: TProcessorInfoComponent;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
function GetWin32_PhysicalMediaInfo:string;
end;
var
Form1: TForm1;
implementation
{$R *.frm}
function TForm1.GetWin32_PhysicalMediaInfo:string;
const
WbemUser ='';
WbemPassword ='';
WbemComputer ='localhost';
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVARIANT;
FWMIService : OLEVARIANT;
FWbemObjectSet: OLEVARIANT;
FWbemObject : OLEVARIANT;
oEnum : IEnumvariant;
lw : LongWord;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PhysicalMedia','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, lw) = 0 do
begin
try
if not VarIsNull(FWbemObject.Properties_.Item('SerialNumber').Value) then
begin
result:=FWbemObject.Properties_.Item('SerialNumber').Value;
Memo1.Lines.Add(result); //<=== for test Only
end;
except
end;
end;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
GetWin32_PhysicalMediaInfo;
end;
end.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。