JSI Tip 8180. When was Windows installed?


I first described the InstallDate Value Name in tip 0664.

I have scripted WhenInstalled.bat to return the Year Month Day Hour Minute Seconds when Windows was installed.

NOTE: Since the InstallDate Value Name is a REG_DWORD data type, the range of values is 0 - 2147483647 (2**31 - 1), which corresponds to January 1, 1970 00:00:00 - January 19, 2038 03:14:07.

NOTE: WhenInstalled.bat uses REG.EXE, either build-in to your operating system, or from the Support\Tools folder of the operating system installation CD-ROM.

NOTE: WhenInstalled.bat uses Ritchie Lawrence's SecsToDate.bat, provided here. It must be installed in a folder that is in your PATH.

The syntax for using WhenInstalled.bat is:

call WhenInstalled Year Month Day Hour Minute Seconds

Where:

Year    is a call directed environment variable that will contain the 4 digit year.
Month   is a call directed environment variable that will contain the 2 digit month.
Day     is a call directed environment variable that will contain the 2 digit day.
Hour    is a call directed environment variable that will contain the 2 digit hour.
Minute  is a call directed environment variable that will contain the 2 digit minute.
Seconds is a call directed environment variable that will contain the 2 digit Seconds.
WhenInstalled.bat contains:
@echo off
if \{%6\}==\{\} @echo Syntax: call WhenInstalled Year Month Day Hour Minute Seconds&goto :EOF
setlocal
Set qry=reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v InstallDate
for /f "Tokens=3" %%i in ('%qry%^|Findstr /i /c:"InstallDate"') do (
 set InstallDate=%%i
)
call SecsToDate %InstallDate% year month day hour minute seconds
endlocal&set %1=%year%&set %2=%month%&set %3=%day%&set %4=%hour%&set %5=%minute%&set %6=%seconds%
SecsToDate.bat contains:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::SecsToDate %secs% yy mm dd hh nn ss
::
:: By:   Ritchie Lawrence, updated 2002-07-24. Version 1.1
::
:: Func: Returns a calendar date and time of day from the number of
::       elapsed seconds since 1st January 1970 00:00:00. For NT4/2K/XP.
:: 
:: Args: %1 seconds used to create calendar date and time of day (by val)
::       %2 var to receive year, 4 digits for all typical dates (by ref)
::       %3 var to receive month, 2 digits, 01 to 12 (by ref)
::       %4 var to receive day of month, 2 digits, 01 to 31 (by ref)
::       %5 var to receive hours, 2 digits, 00 to 23 (by ref)
::       %6 var to receive minutes, 2 digits, 00 to 59 (by ref)
::       %7 var to receive seconds, 2 digits, 00 to 59 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set /a i=%1,ss=i%%60,i/=60,nn=i%%60,i/=60,hh=i%%24,dd=i/24,i/=24
set /a a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
(if %hh% LSS 10 set hh=0%hh%)&(if %nn% LSS 10 set nn=0%nn%)
if %ss% LSS 10 set ss=0%ss% 
endlocal&set %7=%ss%&set %6=%nn%&set %5=%hh%&^
set %4=%dd%&set %3=%mm%&set %2=%yy%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish