如何判断当前系统的安装日期/时间?(100分)

  • 主题发起人 主题发起人 ganbaba
  • 开始时间 开始时间
G

ganbaba

Unregistered / Unconfirmed
GUEST, unregistred user!
听别人说有这方面的API,请教
 
系统目录的创建时间和修改时间<br>或者一个系统核心dll的时间,<br>应该就是安装时间了
 
var<br> &nbsp;Buffer &nbsp; &nbsp; : PByteArray;<br> &nbsp;BufferSize : Integer;<br> &nbsp;s &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: String;<br> &nbsp;i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Integer;<br>begin<br> &nbsp;with TRegistry.Create do try<br> &nbsp; &nbsp;RootKey:=HKey_LOCAL_Machine;<br> &nbsp; &nbsp;OpenKey('Software/Microsoft/Windows/Currentversion',False);<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;BufferSize:=GetDataSize('FirstInstallDateTime');<br> &nbsp; &nbsp; &nbsp;GetMem(Buffer,BufferSize);<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;ReadBinaryData('FirstInstallDateTime',Buffer^,BufferSize);<br> &nbsp; &nbsp; &nbsp; &nbsp;s:='';<br> &nbsp; &nbsp; &nbsp; &nbsp;for i:=0 to BufferSize-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s:=Format('%s%.2x ',[s,Buffer^]);<br> &nbsp; &nbsp; &nbsp; &nbsp;Delete(s,Length(s),1);<br> &nbsp; &nbsp; &nbsp; &nbsp;Label1.Caption:=s;<br> &nbsp; &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; &nbsp;FreeMem(Buffer,BufferSize);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;CloseKey;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;Free;<br> &nbsp;end;<br>end;<br><br>//////////////////////////////////////////////////////////<br><br>function DateInstallWindows (var DateInstall: TDateTime):Boolean; <br>var <br> &nbsp; &nbsp; RegDate: TRegistry; <br> &nbsp; &nbsp; Buffer: &nbsp;Integer; <br>begin <br>Result:=False; <br>RegDate := TRegistry.Create; <br>try <br> &nbsp; &nbsp;RegDate.RootKey := HKEY_LOCAL_MACHINE; <br> &nbsp; &nbsp;if Win32Platform = VER_PLATFORM_WIN32_NT &nbsp;Then <br> &nbsp; &nbsp; &nbsp; &nbsp;Begin <br> &nbsp; &nbsp; &nbsp; &nbsp;if RegDate.OpenKey('Software/Microsoft/Windows NT/CurrentVersion', True) <br> &nbsp; &nbsp; &nbsp; &nbsp;then <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Begin <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegDate.ReadBinaryData('InstallDate',Buffer, sizeof (Buffer)); <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer))); <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=True; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end <br> &nbsp; &nbsp; &nbsp; &nbsp;end <br> &nbsp; &nbsp;else <br> &nbsp; &nbsp; &nbsp; &nbsp;if RegDate.OpenKey('Software/Microsoft/Windows/CurrentVersion', True) <br> &nbsp; &nbsp; &nbsp; &nbsp;then <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Begin <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegDate.ReadBinaryData('FirstInstallDateTime',Buffer, sizeof (Buffer)); <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer))); <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=True; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end <br> &nbsp;finally <br> &nbsp; &nbsp;RegDate.CloseKey; <br> &nbsp; &nbsp;RegDate.Free; <br> &nbsp;end; <br>end; <br><br>2.用法<br><br>procedure TForm1.BitBtn2Click(Sender: TObject); <br>var <br> &nbsp; TheDate: TDateTime; <br>begin <br>if DateInstallWindows (TheDate) Then Label1.Caption:=DateTimeToStr (TheDate); <br>end;
 
应该有这个API的吧
 

Similar threads

回复
0
查看
804
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部