Solved

get windows install date from registry

Posted on 2004-04-30
7
11,305 Views
Last Modified: 2007-12-19
how do i get the windows install date from the registry ?
I had used this code a long time ago, but it dont work under windows XP even if i point the key to '\SOFTWARE\Microsoft\Windows NT\CurrentVersion' and change the string to read to 'InstallDate'.
Anyone know a way to do this ?

Function GetInstallDate: String;
Var
  di: longint;
  buf: Array [ 0..3 ] Of byte;
Begin
  Result := 'Unknown';
  With TRegistry.Create Do
  Begin
    RootKey := HKEY_LOCAL_MACHINE;
    LazyWrite := True;
    OpenKey ( '\SOFTWARE\Microsoft\Windows\CurrentVersion', False );
    di := readbinarydata ( 'FirstInstallDateTime', buf, sizeof ( buf ) );
    Result := DateTimeToStr ( FileDateToDateTime ( buf [ 0 ] + buf [ 1 ] * 256 + buf [ 2 ] * 65535 + buf [ 3 ] * 16777216 ) );
    Free;
  End;
End;


Cheers
0
Comment
Question by:satmanuk
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10962733
Works fine on My WInXP Professional. What version of XP are you using. Do the keys differ for Pro & Home edition?

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10962747
Sorry, to be more precise, the code you posted works for me. I didn't change a thing.

Shane
0
 
LVL 1

Author Comment

by:satmanuk
ID: 10963080
I get the following error in delphi 6 with windows XP pro with SP 1 installed.

Project1.exe raised execption class ERegistryException with message 'Invalid data type for 'InstallDate''. Process stopped. Use step or run to continue.


Strange

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10963376
place a conditional break here:

 di := readbinarydata ( 'FirstInstallDateTime', buf, sizeof ( buf ) );

and comment out this line:

 Result := DateTimeToStr ( FileDateToDateTime ( buf [ 0 ] + buf [ 1 ] * 256 + buf [ 2 ] * 65535 + buf [ 3 ] * 16777216 ) );

then showMessage(inttostr(di));

what do you get?

Shane
0
 
LVL 1

Author Comment

by:satmanuk
ID: 10963629
with this code

Function GetInstallDate: String;
Var
  di: longint;
  buf: Array [ 0..3 ] Of byte;
Begin
  Result := 'Unknown';
  With TRegistry.Create Do
  Begin
    RootKey := HKEY_LOCAL_MACHINE;
    LazyWrite := True;
    OpenKey ( '\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False );
    di := readbinarydata ( 'InstallDate', buf, sizeof ( buf ) );
//    Result := DateTimeToStr ( FileDateToDateTime ( buf [ 0 ] + buf [ 1 ] * 256 + buf [ 2 ] * 65535 + buf [ 3 ] * 16777216 ) );
showMessage(inttostr(di));
    Free;
  End;
End;

i get the following error
'Invalid data type for 'InstallDate'

0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
ID: 10963678
hmm, it works fo me... im usinf delphi 7 though.

WHen I use ReadDate, i get 'Unknown' ....

SHane
0
 
LVL 1

Author Comment

by:satmanuk
ID: 10963698
yer strange, i used to use this code with delphi 5 on windows 98se and windows me, and it worked.
Never mind will try somthing else i think.
Thanks for your time there
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question