#185742 - 2008-02-26 09:19 PM
I am not sure how to use the @Error Macro
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I have a piece of code returning a "null" / "Empty" value, and i would like to say that if that value is found like an @error then goto error processing or something.
Thanks
Indigo
|
|
Top
|
|
|
|
#185743 - 2008-02-26 09:22 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
KiX does not support NULL
If @ERROR <>0
;Do something
Else
;Quit
EndIf
If Not @ERROR
;Do something
Else
;Quit
EndIf
Is that what you're meaning?
|
|
Top
|
|
|
|
#185747 - 2008-02-26 10:10 PM
Re: I am not sure how to use the @Error Macro
[Re: NTDOC]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
Sometimes when i run WMIuptime UDF it returns a blank value.. I am not sure what this would happen, but to compensate i want to make an error trap to report this error, so i can go look at the computers that are returning blank values.
Indigo
Edited by Indigoseth (2008-02-26 10:11 PM)
|
|
Top
|
|
|
|
#185748 - 2008-02-26 10:14 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
duo
Getting the hang of it
Registered: 2007-10-25
Posts: 61
Loc: iowa
|
Is a null return an actual error from this code? you could also do something like
if $returnvalue=''
;report error
endif
|
|
Top
|
|
|
|
#185749 - 2008-02-27 01:17 AM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
It is probably due to the fact that WMI is disabled/corrupted/broken on the remote PC
Take a look at running this UDF before making a WMI call.
WMIConfirm() - Confirm access and version of WMI
|
|
Top
|
|
|
|
#185761 - 2008-02-27 02:08 PM
Re: I am not sure how to use the @Error Macro
[Re: Richard H.]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Please run this debug-enabled version - define $Host to reference the system that fails, and report back ALL output.
Thanks,
Glenn
$Host = '' ; define host that returns null data
WMIUptime($Host)[4] ?
@ERROR ' / ' @SERROR ?
;;
;;======================================================================
;;
;;FUNCTION WMIUptime()
;;
;;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.1 / 2007/04/05 - Authentication, rename to WMIUptime
;; Adjustment for uptime across timezone changes
;;
;;SYNTAX WMIUptime([host] [,AuthPtr])
;;
;;PARAMETERS host - OPTIONAL - name of system to query
;;
;; AuthPtr - OPTIONAL - pre-authenticated WMI object pointer
;; Use WMIAuthentication() udf to create the AuthPtr value
;; AuthPtr is not needed if user has admin rights
;;
;;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 = ''
;; $Up = WMIUptime($Host)
;; $Host has been up for ' $Up[0] ' days!'
;;
;; $Host = 'server'
;; $objWMI = WMIAuthenticate('computer', 'userid', 'User-P@ss!')
;; $Up = WMIUptime($Host, $objWMI)
;; 'Secure host ' $Host ' has been up for ' $Up[0] ' days!'
;
Function WMIUpTime(OPTIONAL $_Target, OPTIONAL $_pAuth)
Dim $_Bt[3], $_Ct[3], $_U[4] ; time arrays for boot, current, and uptime
Dim $_, $_O ; Index var, Offset flag
Dim $_B, $_C ; boot and current time strings
Dim $_Bo, $_Co ; boot and current time offsets
Dim $objWMIService, $colItems, $objItem ; WMI object vars
$WMIUptime = -1 ; default to invalid value
$_Target = IIf($_Target, $_Target, '.')
If InStr($_Target, '\') $_Target = Join(Split($_Target, '\'), '') EndIf
If $_pAuth
$objWMIService = $_pAuth
Else
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Target + '\root\cimv2')
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
EndIf
$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
'B: ' $_B ?
'C: ' $_C ?
; format is YYYYMMDDhhmmss.ssssss+ooo (or -ooo)
; Get the timezone offset. The offset will not play into the calculation unless
; the timezone switched between reboots, such as going from Standard to DaylightSavings
If InStr($_B, '-') Or InStr($_B, '+')
$_Bo = Val(SubStr($_B, 23)) ; boot timezone offset
$_Co = Val(SubStr($_C, 23)) ; current timezone offset
$_O = ($_Co - $_Bo) * 60 ; find the difference, usually will be zero
EndIf
; 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[1] + 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 - 306
$_B = CDbl($_B) * 86400.0
$_B = $_B + $_Bt[3]
If $_Ct[1] < 3
$_Ct[1] = $_Ct[1] + 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 - 306
$_C = CDbl($_C) * 86400.0
$_C = $_C + $_Ct[3]
; Calculate uptime as cTime, then convert to days / hours / minutes / seconds
$_ = $_C - $_B + $_O
$_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
$WMIUptime = $_U
EndFunction
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#185771 - 2008-02-27 05:10 PM
Re: I am not sure how to use the @Error Macro
[Re: Glenn Barnas]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I will look into the error codes when i have the time,
Thanks Doc for the WMICheck I included this as a fail safe to see if it will weed out the systems that are giving me null values.
Indigo
|
|
Top
|
|
|
|
#185774 - 2008-02-27 08:08 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I placed the Wmiconfirm.udf in my program and incapsolated the guts of the program inside of an if statement.
$WMICheck = WMIConfirm('$computer')
If $WMICheck
Do what i need done.
else
Do Error proccessing.
endif
Will this work as intended because i notice it is still letting the null information through. 
Indigo
Edited by Indigoseth (2008-02-27 08:09 PM)
|
|
Top
|
|
|
|
#185775 - 2008-02-27 08:15 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
Glenn i ran the script you posted earlier, and it comes back with an error code of 0 saying it completed.
however, i did have to change a couple things to get it to work. Please review, and tell me if what i changed was ok.
$Host = '$computer' ; define host that returns null data
$uptime = WmiUptime($Host) ?
@ERROR ' / ' @SERROR ?
? $uptime[0]
Sleep 5
Thanks
Indigo
P.S. when i print the output for WMIUptime do i need to specify the [0]?
Edited by Indigoseth (2008-02-27 08:16 PM)
|
|
Top
|
|
|
|
#185803 - 2008-02-28 04:52 PM
Re: I am not sure how to use the @Error Macro
[Re: NTDOC]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I re-ran the code and the message that was returned was:
0 / The operation completed successfully
I didn't see the other items that you mentioned would be there.
Indigo
|
|
Top
|
|
|
|
#185813 - 2008-02-28 07:31 PM
Re: I am not sure how to use the @Error Macro
[Re: Glenn Barnas]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I am not getting the result your asking for.
#185761 - This is the post number i copied the code from. I am positive i have all the code. I tried running it from a batch file and from a command prompt.
Any other ideas on what i should try?
Indigo
|
|
Top
|
|
|
|
#185814 - 2008-02-28 07:35 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
To address the failing to connect, I used WMIConfirm in my original script to catch systems that the WMI Wasn't working? and the system still had the issue of the null value. It passed the WMI Confirms check?
Indigo
|
|
Top
|
|
|
|
#186013 - 2008-03-06 02:13 PM
Re: I am not sure how to use the @Error Macro
[Re: Indigoseth]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I don't understand... is everyone dropping this?
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 640 anonymous users online.
|
|
|