Another question elligeable for a 'code-challenge': here are some source code executables to answer the problem, but they are not complete.
Will you find a vb script that anyone can execute on his/her computer, with the expected result ?
systeminfo|find /i "original"
would give you the actual date... not the number of seconds ;)
But (caveat), as noted in the 2021 comments by Salman A and AutoMattTick
If Windows was updated to a newer version, this seems to give the date on which Windows was RE-installed.
As Sammy comments, find /i "install"
gives more than you need.
And this only works if the locale is English: It needs to match the language.
For Swedish this would be "ursprungligt
" and "ursprüngliches
" for German.
Andy Gauge proposes in the comments:
shave 5 characters off with
systeminfo|find "Original"
In Windows PowerShell script, you could just type:
PS > $os = get-wmiobject win32_operatingsystem
PS > $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy"
By using WMI (Windows Management Instrumentation)
If you do not use WMI, you must read then convert the registry value:
PS > $path = 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion'
PS > $id = get-itemproperty -path $path -name InstallDate
PS > $d = get-date -year 1970 -month 1 -day 1 -hour 0 -minute 0 -second 0
## add to hours (GMT offset)
## to get the timezone offset programatically:
## get-date -f zz
PS > ($d.AddSeconds($id.InstallDate)).ToLocalTime().AddHours((get-date -f zz)) -f "MM/dd/yyyy"
The rest of this post gives you other ways to access that same information. Pick your poison ;)
In VB.Net that would give something like:
Dim dtmInstallDate As DateTime
Dim oSearcher As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
For Each oMgmtObj As ManagementObject In oSearcher.Get
dtmInstallDate =
ManagementDateTimeConverter.ToDateTime(CStr(oMgmtO bj("InstallDate")))
Next
In Autoit (a Windows scripting language), that would be:
;Windows Install Date
;
$readreg = RegRead("HKLMSOFTWAREMICROSOFTWINDOWS NTCURRENTVERSION", "InstallDate")
$sNewDate = _DateAdd( 's',$readreg, "1970/01/01 00:00:00")
MsgBox( 4096, "", "Date: " & $sNewDate )
Exit
In Delphy 7, that would go as:
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 ( 'SOFTWAREMicrosoftWindows NTCurrentVersion', 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;
As an alternative, CoastN proposes in the comments:
As the system.ini-file
stays untouched in a typical windows deployment, you can actually get the install-date by using the following oneliner:
(PowerShell): (Get-Item "C:Windowssystem.ini").CreationTime