Solved

get windows install date from registry

Posted on 2004-04-30
7
11,254 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now