怎么读取系统安装日期与开机时间呢?

shylsx 2003-07-22 09:04:04
怎么读取系统安装日期与开机时间呢?我知道用注册表,但是我不知道怎么读取这样的类型。请指点我!
...全文
197 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
peter207 2003-07-23
  • 打赏
  • 举报
回复
mark
Eastunfail 2003-07-23
  • 打赏
  • 举报
回复
给个刚才写的代码。这是一个例子,呵呵,可以得到开机的时间。不过如果你的电脑连续开机了几天,那么这个代码你就要修改修改了。不过估计你看得懂,也好改

var t:integer;
sTime: TSystemTime;
_ms,_s,_m,_h:integer;
begin
GetLocalTime(sTime);
t:=GetTickCount();
t:=sTime.wSecond *1000+sTime.wMilliseconds +sTime.wMinute *60000+sTime.wHour*3600000-t;
_ms:=t mod 1000;//得到微秒
t:=(t-_ms) div 1000;
_s:=t mod 60;//得到秒
t:=(t-_s) div 60;
_m:=t mod 60;//得到分
t:=(t-_m) div 60;
_h:=t mod 60;//得到小时
ShowMessage(Format('开机时间:%d:%d:%d.%d',[_h,_m,_s,_ms]));
end;
李_军 2003-07-23
  • 打赏
  • 举报
回复
系统安装时间
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:=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;

2.用法

procedure TForm1.BitBtn2Click(Sender: TObject);
var
TheDate: TDateTime;
begin
if DateInstallWindows (TheDate) Then Label1.Caption:=DateTimeToStr (TheDate);
end;

shylsx 2003-07-23
  • 打赏
  • 举报
回复
OK,多谢大家。我相信我能解决了。现在就给分。
BeyondStudio 2003-07-22
  • 打赏
  • 举报
回复
安装日期读注册表啊,开机时间在论坛里很多,自己找吧。

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧