Solved

get windows install date from registry

Posted on 2004-04-30
7
11,292 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 64
Reconfigure Delphi Install? 2 60
Tembedded WB animatid gifs not animated on some pcs 2 83
How to load 2 images in same column in Delphi 2 57
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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