[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11354
  • Last Modified:

get windows install date from registry

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
satmanuk
Asked:
satmanuk
  • 4
  • 3
1 Solution
 
shaneholmesCommented:
Works fine on My WInXP Professional. What version of XP are you using. Do the keys differ for Pro & Home edition?

Shane
0
 
shaneholmesCommented:
Sorry, to be more precise, the code you posted works for me. I didn't change a thing.

Shane
0
 
satmanukAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
shaneholmesCommented:
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
 
satmanukAuthor Commented:
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
 
shaneholmesCommented:
hmm, it works fo me... im usinf delphi 7 though.

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

SHane
0
 
satmanukAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now