|
获取设备ID:- function GetDeviceUniqueID(AppData:LPCWSTR; cbApplictionData:Integer; dwDeviceIDVersion:Integer;
- var deviceIDOuput; var pcbDeviceIDOutput:DWORD):Integer; external 'coredll.dll' name 'GetDeviceUniqueID';
-
- function GetDeviceID: string;
- var
- AppData: array[0..19] of WideChar;
- DeviceID : array[0..19] of Byte;
- Count: DWORD;
- s: string;
- Res, i:Integer;
- begin
- //not sure about Unicode
- AppData := Utf8Decode('MY_SIG');//any string you like
- Count := SizeOf(DeviceID);
- FillChar(DeviceID, Count, #0);
- Res := GetDeviceUniqueID(AppData, SizeOF(AppData), 1, DeviceID, Count);
- if Res = 0 then
- begin
- Result := '';
- for i := 0 to Count -1 do
- begin
- if (i > 0) and ((i mod 2) = 0) then
- Result := Result + '-'; //add space make the string wrap in label
- Result := Result + IntToHex(DeviceID[i], 2);
- end;
- end
- else
- Result := '';//error accord
- // you can MD5 it with your string
- // Result := MD5Print(MD5Buffer(DeviceID, Count));
- end;
复制代码 获取设备名称:- function GetDeviceName: string;
- var
- aReg:TRegistry;
- begin
- aReg := TRegistry.Create(KEY_READ);
- try
- aReg.RootKey := HKEY_LOCAL_MACHINE;
- aReg.OpenKey('Ident', False);
- if aReg.ValueExists('Name') then
- Result := aReg.ReadString('Name')
- else
- Result := 'GUEST';
- finally
- aReg.Free;
- end;
- end;
复制代码 |
|