Mega Code Archive

 
Categories / Delphi / System
 

When was installed my Windows

Title: When was installed my Windows? Question: When was installed my Windows? Answer: How much of we have asked us, the date in which was installed the Windows, some will say so that serves that datum, I simply answer that I use to validate the certain programs expiration and to avoid the piracy. This date undoubtedly it can not be altered, (well at least I do not know someone that it may have made), therefore is converted into an excellent reference data. Without preambles here I present the form of determining this date. 1. Create a function or procedure that return 2 values a) A value Boolean to determine if the task has been fulfilled successfully. b) A value TDateTime, that will contain the installation date, obviously if the previous returns True. In my case I create a function, but is I left them to your decision. function DateInstallWindows (var DateInstall: TDateTime):Boolean; var RegDate: TRegistry; Buffer: Integer; begin Result:=False; RegDate := TRegistry.Create; try RegDate.RootKey := HKEY_LOCAL_MACHINE; if Win32Platform = VER_PLATFORM_WIN32_NT Then Begin if RegDate.OpenKey('Software\Microsoft\Windows NT\CurrentVersion', True) then Begin RegDate.ReadBinaryData('InstallDate',Buffer, sizeof (Buffer)); DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer))); Result:=True; end end else if RegDate.OpenKey('Software\Microsoft\Windows\CurrentVersion', True) then Begin RegDate.ReadBinaryData('FirstInstallDateTime',Buffer, sizeof (Buffer)); DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer))); Result:=True; end finally RegDate.CloseKey; RegDate.Free; end; end; 2. Here I call the function. The method must work fine with Win9x and NT but I don't know if it work with W2K. procedure TForm1.BitBtn2Click(Sender: TObject); var TheDate: TDateTime; begin if DateInstallWindows (TheDate) Then Label1.Caption:=DateTimeToStr (TheDate); end; 3. That's all folk. Best regards.