#152814 - 2005-12-05 10:56 AM
Erroneous zeros in the log file
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Hi All, I have written a function which writes all the errors generated into an ERROR LOG instead of displaying it on the screen. Code:
Function LogErrors($ErrorValue, optional $MiscInfo1, optional $MiscInfo2)
If RedirectOutput($ErrorFile) = 0 If $ErrorValue = $ERROR_ACCESS_DENIED ? "Access is Denied for computer $MiscInfo1" Else If $ErrorValue = $ERROR_BAD_NETPATH ? "The network path was not found for the computer $MiscInfo1" Else ? "File not opened, error code: [" + $ErrorValue + "]" If $MiscInfo1 > 0 ? $MiscInfo1 EndIf EndIf EndIf
EndFunction
BUT the surprising thing that in the error statements, some ZEROS also got appended. (I don't know how )
here's a partial error log:
The network path was not found for the computer compname129A0 Access is Denied for computer compname129B00
First statement has 1 zero while 2nd statement has 2 zeros. How are these zeros getting appended. Plz. let me know.
N.B. $ErrorFile is the name of the Error File. Thank you.
|
|
Top
|
|
|
|
#152818 - 2005-12-05 12:57 PM
Re: Erroneous zeros in the log file
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Quote:
instead of doing this complex error reporting UDF, why don't you just display the errors after each of the functions and commands. if you want errorlog udf, something simple as the one below should do exactly what you already do: Code:
function LogErrors() if @error $errorString = @wksta + "--> " + @serror + " (" + @error + ")" $=RedirectOutput($ErrorFile) $errorString ? endif endfunction
Thank you for the help. It is far better than my function. I have to learn a lot. BUT still I am getting the same problem. I am still getting ZEROS in the log file.
Should I put Code:
$rc = ? "File not opened, error code: [" + $ErrorValue + "]" If NOT $rc=0 ? $rc EndIf
BUT this gives me an error. Plz. let me know what is missing?
|
|
Top
|
|
|
|
#152822 - 2005-12-06 08:30 AM
Re: Erroneous zeros in the log file
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Quote:
k, if you don't want the extra non-silenced zeros, use this version: Code:
function LogErrors() if @error $errorString = @wksta + "--> " + @serror + " (" + @error + ")" $=RedirectOutput($ErrorFile) $errorString ? $=RedirectOutput("") endif endfunction
Thanks a lot for the code, Joel. It has removed all the zeros from the log file, BUT i dont know why does it still print zeros on the CONSOLE. 
Here's the code. (I have written a script to check a registry key of some computers. either the computer name can be mentioned in the script itself or it can be read from an input file)
Code:
CLS ;Debug On Break On
$NotInstalled = "Not Installed.log" $Installed = "Installed.log" $ErrorFile = "Errors.log" $InputFile = "computerlist.txt"
$RegistryValue = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\Client\Options' $RegistryKey = 'DumpsterAlwaysOn' $RegData = '01'
$FileNames = $Installed, $NotInstalled, $ErrorFile For Each $Item In $FileNames If Exist($Item) Del $Item EndIf Next
;THIS IS THE LIST OF COMPUTERS FOR WHICH REGISTRY HAS TO BE CHECKED
$ComputerName1 = 'COMPUTER1' $ComputerName2 = 'COMPUTER2' $ComputerName3 = 'COMPUTER3' $ComputerName4 = 'COMPUTER4'
$CompNames = $ComputerName1, $ComputerName2, $ComputerName3, $ComputerName4 For Each $Item In $CompNames CheckRegValue($Item) Next
;THE LIST OF COMPUTERS HAS ALSO BEEN MENTIONED IN A .TXT FILE
/* If Open(3, $InputFile) = 0 $x = ReadLine(3) While @ERROR = 0 ;? "Line read: [" + $x + "]" CheckRegValue($x) $x = ReadLine(3) Loop Close (3) Else Beep $msg=messagebox("$InputFile not accessible","Check Registry key",0) ;LogErrors(@ERROR,"Input File not accessible") EndIf */
Function CheckRegValue($Item)
$Value = '\\' + $Item + '\' + $RegistryValue $VersionType = ReadValue($Value,$RegistryKey) ;$msg=messagebox("$VersionType,"version type",0) If @ERROR=0 ;$msg=messagebox($VersionType,"version type",0) Else LogErrors(@ERROR,$Item) EndIf If VAL($VersionType) = VAL($RegData)
$Handle1 = FreeFileHandle() If Open( $Handle1 , $Installed , 5 ) = 0 $z = WriteLine($Handle1,@CRLF + $Item) Close ($Handle1) ;Else ;? "failed to open file $Installed with Handle1, error code : [" + @ERROR + "]" EndIf
Else
$Handle2 = FreeFileHandle() If Open( $Handle2 , $NotInstalled , 5 ) = 0 If $VersionType = "" $VersionType ='N/A' EndIf $z = WriteLine($Handle2,@CRLF + $Item + " --> " + " Registry key is: " + $VersionType) Close ($Handle2) ;Else ;? "failed to open file $NotInstalled with Handle2, error code : [" + @ERROR + "]" EndIf EndIf
EndFunction
Function LogErrors($ErrorValue, optional $MiscInfo1, optional $MiscInfo2)
If @ERROR $errorString = $MiscInfo1 + "--> " + @serror + " (" + @error + ")" $=RedirectOutput($ErrorFile) $errorString ? $=RedirectOutput("") EndIf
EndFunction
one more thing, if a computer is NOT connected to the network, it takes around 30 seconds to display the reason. Is there any method of reducing this delay.
ReadValue function does not specify any time for pinging to a computer. Thank you
|
|
Top
|
|
|
|
#152829 - 2005-12-07 12:20 AM
Re: Erroneous zeros in the log file
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Quote:
and mart was faster again...
His wife may not like that...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1110 anonymous users online.
|
|
|