'cocher la référence Microsoft WMI Scripting v1.2 Library
Sub Date_installation_OS()
Dim strComputer As String
Dim objWMIService As SWbemServicesEx
Dim colOperatingSystems As SWbemObjectSet
Dim objOperatingSystem As WbemScripting.SWbemObjectEx
Dim DateInstal, PosSigne, NegSigne
Dim LaDate As Date
Dim Heure As Date
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.Execquery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
DateInstal = objOperatingSystem.InstallDate
If DateInstal Like "*+*" Or DateInstal Like "*-*" Then
PosSigne = InStr(1, DateInstal, "+")
NegSigne = InStr(1, DateInstal, "-")
End If
Select Case True
Case PosSigne > 0
HeureGmt = CDbl(Mid(DateInstal, PosSigne + 1, Len(DateInstal) - PosSigne))
Heure = TimeSerial(Mid(DateInstal, 9, 2) + HeureGmt / 60, _
Mid(DateInstal, 11, 2), Mid(DateInstal, 13, 2))
Case NegSigne > 0
HeureGmt = CDbl(Mid(DateInstal, NegSigne + 1, Len(DateInstal) - NegSigne))
Heure = TimeSerial(Mid(DateInstal, 9, 2) - HeureGmt / 60, _
Mid(DateInstal, 11, 2), Mid(DateInstal, 13, 2))
Case Else
Heure = TimeSerial(Mid(DateInstal, 9, 2), _
Mid(DateInstal, 11, 2), Mid(DateInstal, 13, 2))
End Select
LaDate = DateSerial(Mid(DateInstal, 1, 4), Mid(DateInstal, 5, 2), Mid(DateInstal, 7, 2))
MsgBox "Date d'installation du système d'exploitation sur l'ordinateur :" & vbCrLf & _
"le " & LaDate & " à " & Heure
Next
End Sub