#171308 - 2006-12-11 05:48 AM
Test post
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
test post - Posted as HTML Edits of the UDF post work! (edited about 9 times so far) Generated with PPCL - PostPrep Command Line ppcl.kix -s:timestamp.udf -c Generates timestamp.htm and loads the clipboard CAUTION! This UDF has extra lines to test certain formatting capabilities, and the Long_Line_Break process. If anyone uses this UDF, be sure to remove any text after the EndFunction as it is not part of the UDF!;; ;;====================================================================== ;; ;;FUNCTION Uptime() ;; ;;ACTION Reads the boot and current time from a defined host and ;; calculates the length of time the system has been up. ;; ;;AUTHOR Glenn Barnas ;; ;;VERSION 1.0 / 2006/11/21 ;; ;;SYNTAX Uptime(host) ;; ;;PARAMETERS host - OPTIONAL - name of system to query ;; ;;REMARKS Gets both the boot and local time from the remote system, ;; eliminating issues with timezone differences between target ;; and client. ;; ;;RETURNS Array containing Days, Hours, Minutes, and Seconds of uptime. ;; Also returns the cTime value in element 4 ;; ;;DEPENDENCIES WMI support ;; ;;TESTED WITH W2K, WXP, W2K3 ;; ;;EXAMPLES $Host = 'computer' ;; $Up = Uptime($Host) ;; $Host ' has been up for ' $Up[0] ' days!' ; function UpTime(OPTIONAL $_Target ) Dim $_Bt [3 ], $_Ct [3 ], $_U [4 ] Dim $_ , $_B , $_C Dim $objWMIService , $colItems , $objItem $_Target = IIf ($_Target , $_Target , '.' ) $objWMIService = GetObject ("winmgmts:\\" + $_Target + "\root\cimv2" ) $colItems = $objWMIService.ExecQuery ("Select * from Win32_OperatingSystem" ,,48 ) For each $objItem in $colItems $_B = $objItem.LastBootUpTime ; host-local boot time $_C = $objItem.LocalDateTime ; host-local current time ; format is YYYYMMDDhhmmss.ssssss+ooo (or -ooo) ; strip off the fractional seconds and time zone offset value $_B = Split ($_B , '.' )[0 ] $_C = Split ($_C , '.' )[0 ] ; format is now YYYYMMDDhhmmss - put into array $_Bt [0 ] = Val (SubStr ($_B , 1 , 4 )) - 2000 $_Bt [1 ] = Val (SubStr ($_B , 5 , 2 )) $_Bt [2 ] = Val (SubStr ($_B , 7 , 2 )) $_Bt [3 ] = 1.0 * SubStr ($_B ,13 ) + 60.0 * SubStr ($_B ,11 ,2 ) + 3600.0 * SubStr ($_B ,9 ,2 ) $_Ct [0 ] = Val (SubStr ($_C , 1 , 4 )) - 2000 $_Ct [1 ] = Val (SubStr ($_C , 5 , 2 )) $_Ct [2 ] = Val (SubStr ($_C , 7 , 2 )) $_Ct [3 ] = 1.0 * SubStr ($_C ,13 ) + 60.0 * SubStr ($_C ,11 ,2 ) + 3600.0 * SubStr ($_C ,9 ,2 ) ; Convert dates to Days, then convert to seconds and add the time value If $_Bt [1 ] < 3 $_Bt [1 ] = $_Bt [0 ] + 12 $_Bt [0 ] = $_Bt [0 ] - 1 EndIf $_B = $_Bt [2 ] + ( 153 * $_Bt [1 ] - 457 ) / 5 + 365 * $_Bt [0 ] + $_Bt [0 ] / 4 - $_Bt [0 ] / 100 + $_Bt [0 ] / 400 - 30 $_B = CDbl ($_B ) * 86400.0 $_B = $_B + $_Bt [3 ] If $_Ct [1 ] < 3 $_Ct [1 ] = $_Ct [0 ] + 12 $_Ct [0 ] = $_Ct [0 ] - 1 EndIf $_C = $_Ct [2 ] + ( 153 * $_Ct [1 ] - 457 ) / 5 + 365 * $_Ct [0 ] + $_Ct [0 ] / 4 - $_Ct [0 ] / 100 + $_Ct [0 ] / 400 - 30 $_C = CDbl ($_C ) * 86400.0 $_C = $_C + $_Ct [3 ] ; Calculate uptime as cTime, then convert to days / hours / minutes / seconds $_ = $_C - $_B $_U [4 ] = $_ ; return the cTime value $_U [0 ] = Int ($_ / 86400 ) $_ = $_ Mod 86400 $_U [1 ] = $_ / 3600 $_ = $_ Mod 3600 $_U [2 ] = $_ / 60 $_U [3 ] = $_ Mod 60 Next $Uptime = $_U EndFunction "String" 'String' @MACRO Long Line: $_B = $_Bt [2 ] + ( 153 * $_Bt [1 ] - 457 ) / 5 + 365 * $_Bt [0 ] + $_Bt [0 ] / 4 - $_Bt [0 ] / 100 + $_Bt [0 ] / 400 - 306 - $_B = $_Bt [2 ] + ( 153 * $_Bt [1 ] - 457 ) / 5 + 365 * $_Bt [0 ] + $_Bt [0 ] / 4 - $_Bt [0 ] / 100 + $_Bt [0 ] / 400 - 306 + $_B = $_Bt [2 ] + ( 153 * $_Bt [1 ] - 457 ) / 5 + 365 * $_Bt [0 ] + $_Bt [0 ] / 4 - $_Bt [0 ] / 100 + $_Bt [0 ] / 400 - 30
Edited by Glenn Barnas (2006-12-11 01:53 PM )
_________________________
Actually I
am a Rocket Scientist!
Top
Moderator: Arend_ , Allen , Jochen , Radimus , Glenn Barnas , ShaneEP , Ruud van Velsen , Mart
0 registered
and 2141 anonymous users online.