标签:
{ procedure Time_T_to_FileTime(const time_in: DWORD; const pft: PFILETIME); inline; var X: Int64; begin x := LongLong(time_in) * 10000000 + 116444736000000000; //$19db1ded53ea710; pft^.dwHighDateTime := DWORD((x shr 32) and $0FFFFFFFF); pft^.dwLowDateTime := DWORD(x and $0FFFFFFFF); end; function Time_T_2_DateTime(const time_in: DWORD): TDateTime; inline; var ft: FILETIME; st: SYSTEMTIME; begin Time_T_to_FileTime(time_in, @ft); FileTimeToLocalFileTime(ft, ft); FileTimeToSystemTime(ft, st); Result := SystemTimeToDateTime(st); end; } { //系统安装时间 function DateInstallWindows(var DateInstall: TDateTime): Boolean; var RegDate: TRegistry; Buffer: Integer; begin Result := False; RegDate := TRegistry.Create; try RegDate.RootKey := HKEY_LOCAL_MACHINE; if Win32Platform = VER_PLATFORM_WIN32_NT then begin if RegDate.OpenKey(‘Software\Microsoft\Windows NT\CurrentVersion‘, True) then begin RegDate.ReadBinaryData(‘InstallDate‘, Buffer, sizeof(Buffer)); DateInstall := Time_T_2_DateTime(Buffer); // DateInstall := StrToDateTime(FormatDateTime(‘dd/mm/yyyy hh:nn‘, FileDateToDateTime(Buffer))); Result := True; end end else if RegDate.OpenKey(‘Software\Microsoft\Windows\CurrentVersion‘, True) then begin RegDate.ReadBinaryData(‘FirstInstallDateTime‘, Buffer, sizeof(Buffer)); // DateInstall := StrToDateTime(FormatDateTime(‘dd/mm/yyyy hh:nn‘, FileDateToDateTime(Buffer))); Result := True; end finally RegDate.CloseKey; RegDate.Free; end; end; } //用法 { procedure TForm1.BitBtn2Click(Sender: TObject); var TheDate: TDateTime; begin if DateInstallWindows (TheDate) Then Label1.Caption:=DateTimeToStr (TheDate); end; } //使用(假定注册表读出来的时间值是:1203249216): //Delphi(Pascal) code //ShowMessage(FormatDatetime(‘yyyy-mm-dd hh:nn:ss‘,Time_T_2_DateTime(1203249216))); { var Buffer: PByteArray; BufferSize: Integer; s: string; i: Integer; begin with TRegistry.Create do try RootKey := HKey_LOCAL_Machine; OpenKey(‘Software\Microsoft\Windows\Currentversion‘, False); try BufferSize := GetDataSize(‘FirstInstallDateTime‘); GetMem(Buffer, BufferSize); try ReadBinaryData(‘FirstInstallDateTime‘, Buffer^, BufferSize); s := ‘‘; for i := 0 to BufferSize - 1 do s := Format(‘%s%.2x ‘, [s, Buffer^[i]]); Delete(s, Length(s), 1); Label1.Caption := s; finally FreeMem(Buffer, BufferSize); end; finally CloseKey; end; finally Free; end; end; ////////////////////////////////////////////////////////// }
标签:
原文地址:http://www.cnblogs.com/CodeGear/p/4760889.html