我正在尝试制作delphi程序服务器和客户端,以便保护我的应用程序并确保所有用户都受到控制,我应该给他们一个无法更改的唯一密钥以不丢失它们句柄,所以我认为它应该是硬盘驱动器序列号 + Bios SN,但我记得移除主板电池时可以更改 Bios,所以它不会工作。所以我现在的选择是硬盘真实序列号我尝试下面的代码来获取它,但它没有用
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,WbemScripting_TLB,ActiveX;
type
TForm4 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
function GetWMIstring (wmiHost, wmiClass, wmiProperty : string):string;
var // These are all needed for the WMI querying process
Locator: ISWbemLocator;
Services: ISWbemServices;
SObject: ISWbemObject;
ObjSet: ISWbemObjectSet;
SProp: ISWbemProperty;
Enum: IEnumVariant;
Value: Cardinal;
TempObj: OleVariant;
SN: string;
begin
try
Locator := CoSWbemLocator.Create; // Create the Location object
// Connect to the WMI service, with the root\cimv2 namespace
Services := Locator.ConnectServer(wmiHost, 'root\cimv2', '', '', '','', 0, nil);
ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL',
wbemFlagReturnImmediately and wbemFlagForwardOnly , nil);
Enum := (ObjSet._NewEnum) as IEnumVariant;
while (Enum.Next(1, TempObj, Value) = S_OK) do
begin
SObject := IUnknown(tempObj) as ISWBemObject;
SProp := SObject.Properties_.Item(wmiProperty, 0);
if VarIsNull(SProp.Get_Value) then
result := ''
else
begin
SN := SProp.Get_Value;
result := SN;
end;
end;
except // Trap any exceptions (Not having WMI installed will cause one!)
on exception do
result := '';
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
var
x:string;
Y:string;
begin
X:=GetWMIstring('','Win32_BIOS','SerialNumber');
Y:=GetWMIstring('','Win32_DiskDrive"','SerialNumber') ;
ShowMessage(x+';'+y);
end;
end.
*所以请任何人纠正我的代码或给我另一个想法最好的问候*