This article will describe how to determine the operating system installation date using wmi with vb.net source code.The wmi object is created and queried for the operating system installation date. Here is the example source code
Private Sub setOSInstallDate() Try Dim myAlias As String = "Win32_OperatingSystem" Dim strOut As String = "" Dim colItems = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from " & myAlias) 'strOut = strOut & "The left is Property Name , After : The value" Dim dateString As String = "" For Each objComputer In colItems dateString = objComputer.InstallDate 'MsgBox(dateString) 'as yyyymmddhhmmss.000000+330 Next Dim year = Mid(dateString, 1, 4) 'MsgBox(year) Dim mth = Mid(dateString, 5, 2) 'MsgBox(mth) Dim mdate = Mid(dateString, 7, 2) Dim mHr = Mid(dateString, 9, 2) Dim mMin = Mid(dateString, 11, 2) Dim mSS = Mid(dateString, 13, 2) 'MsgBox(mdate) Dim firstDate, msg As String Dim secondDate As Date 'to convert to date the required string "dd-mm-yyyy hh:mm:ss" firstDate = mdate & "-" & mth & "-" & year & " " & mHr & ":" & mMin & ":" & mSS 'secondDate = CDate(firstDate) 'MsgBox(secondDate.ToString) strOSInstallDate = firstDate 'secondDate.ToString Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
That is all.
If you liked this article please do leave a reply and share it with friends.
Thanks.