Solved

get windows install date from registry

Posted on 2004-04-30
7
11,318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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