Temporary Code Windows installation date

Source: Internet
Author: User

{procedure Time_t_to_filetime (const Time_in:dword; const pft:pfiletime); Inline;var x:int64;begin X: = Longlong (ti ME_IN) * 10000000 + 116444736000000000;  $19db1ded53ea710;  Pft^.dwhighdatetime: = DWORD ((x shr) 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; }{System Installation Time 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\CurrentVersi        On ', 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;}  //usage{procedure Tform1.bitbtn2click (sender:tobject);  var thedate:tdatetime;  Begin if Dateinstallwindows (thedate) then Label1.caption:=datetimetostr (thedate);  End }//use (assuming the time value read out by the registry is: 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; ////////////////////////////////////////////////////////// }

Temporary Code Windows installation date

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.