If you are already getting boottime this should be simple. Assuming you are using WMI, you also want to get the localtime on the host and not what you are scanning from so the uptime is accurate. This is what I wrote on an internal program I use.
Public Function GetUptime() As String
Try
Dim searcher As New ManagementObjectSearcher(“\” & hostname & “rootCIMV2”, “SELECT * FROM Win32_OperatingSystem”)
Dim Bootime As DateTime
Dim localtime As DateTime
For Each queryObj As ManagementObject In searcher.Get()
Bootime = System.Management.ManagementDateTimeConverter.ToDateTime(queryObj(“LastBootUpTime”))
localtime = System.Management.ManagementDateTimeConverter.ToDateTime(queryObj(“LocalDateTime”))
Next
Dim TS As TimeSpan = localtime – Bootime
‘Nice Clean output
Dim time As String = TS.Days.ToString & ” Day(s) ” & TS.Hours & ” Hour(s) ” & TS.Minutes.ToString & ” Minute(s) ” & TS.Seconds.ToString & ” Seconds”
Return time
Catch ex As Exception
Return “Error: ” & ex.Message.Split(“(“)(0)
End Try
End Function