I am trying to make a Delphi Server And Client program to protect my application and make sure that all users are under control. I have to give them a unique key that cannot be changed so as not to lose them. there must be a serial number HDD + Bios SN, but I remember that Bios can be changed when the motherboard is removed Battery, so it will not work. so I am choosing the HDD Real serial number now. I am trying to use this code below to get it, but it did not work.
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.
* please, please, can someone fix my code or give me another idea Best attitude *
Anajehad walaa
source share