Un'altra domanda comprensibile per una " sfida del codice ": ecco alcuni eseguibili del codice sorgente per rispondere al problema, ma non sono completi.
Troverai uno script vb che chiunque può eseguire sul proprio computer, con il risultato atteso?
systeminfo|find /i "original"
ti darebbe la data effettiva ... non il numero di secondi;)
Come commenta Sammy , dà più del necessario.
E questo funziona solo se la locale è l'inglese: deve corrispondere alla lingua.
Per lo svedese questo sarebbe " " e " " per il tedesco.find /i "install"
ursprungligt
ursprüngliches
Nello script di Windows PowerShell , puoi semplicemente digitare:
PS > $os = get-wmiobject win32_operatingsystem
PS > $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy"
Utilizzando WMI ( Strumentazione gestione Windows )
Se non si utilizza WMI, è necessario leggere quindi convertire il valore di registro:
PS > $path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
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"
Il resto di questo post offre altri modi per accedere a quelle stesse informazioni. Scegli il tuo veleno ;)
In VB.Net ciò darebbe qualcosa del tipo:
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 (un linguaggio di scripting Windows), sarebbe:
;Windows Install Date
;
$readreg = RegRead("HKLM\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\", "InstallDate")
$sNewDate = _DateAdd( 's',$readreg, "1970/01/01 00:00:00")
MsgBox( 4096, "", "Date: " & $sNewDate )
Exit
In Delphy 7, sarebbe come:
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;
In alternativa, CoastN propone nei commenti :
Dato che system.ini-file
non viene toccato in una tipica distribuzione di Windows, puoi effettivamente ottenere la data di installazione usando il seguente oneliner:
(PowerShell): (Get-Item "C:\Windows\system.ini").CreationTime