臨時代碼 Windows安裝日期

來源:互聯網
上載者:User

標籤:

{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; ////////////////////////////////////////////////////////// }

 

臨時代碼 Windows安裝日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.