#178470 - 2007-07-26 05:58 PM
Uptime Calculator (New code)
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Found a different way to calculate uptime. keep in mind that for this to work you HAVE to have SNMP and WMI SNMP installled on your system in Windows Components, they are NOT installed by default.
Anyway since it's late and i'm tired I probably calculated it wrong somewhere, if someone likes to test it and help me out here with the calculation I'd be very much obliged.
$strComputer = "."
$objLocator = CreateObject("WbemScripting.SWbemLocator")
$objWMIService = $objLocator.ConnectServer($strComputer, "root/snmp/localhost")
$objNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
$colItems = $objWMIService.Instancesof("SNMP_RFC1213_MIB_system",,$objNamedValueSet)
For each $objItem in $colItems
$x = CDBL($objItem.sysUpTime)
$mili = $x mod 1000
$sec = ($x / 1000) mod 60
$min = ($x / 60000) mod 60
$hour = ($x / 360000) mod 24
"sysUpTime: " + CStr($Hour) + ":" + CStr($min) + ":" + CStr($sec) ?
?
Next
|
|
Top
|
|
|
|
#178528 - 2007-07-27 09:59 PM
Re: Uptime Calculator (New code)
[Re: Arend_]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Since your code retrieves the uptime value directly and simply translates to "human readable" form, it is not subject to timezone offsets. Lonk's code reads the remote boot time, then subtracts that from the LOCAL current time to calculate the uptime. If the two computers are in different time zones, the result would be inaccurate. My UDF gets both boot and current time from the remote computer. This way, both values are relative to each other, and the calculation is correct. With Lonk's UDF, if I reboot a computer on the west coast (I'm on the east coast) and immediatly run the uptime udf, it reports 4 hours and some minutes, due to the 4 hour difference between time zones.
I like your concept, but the reliance on SNMP is an issue for me in my environment. I haven't found a way to obtain a direct uptime value from remote computers without calculations or third party tools (which basically do the same calculations). WMI reports boot time on all platforms that support WMI, but I havent found that it reports uptime on the same platforms.
Bottom line - there's no issue with your UDF other than the need for SNMP.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#178539 - 2007-07-29 04:09 PM
Re: Uptime Calculator (New code)
[Re: Mart]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Thx mart  But I'm into a more solid solution for this, will post more info as I progress
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 1539 anonymous users online.
|
|
|