Hello
I have to test the size of some event logs (Application, Security and System) on a Windows XP machine. In order to do this, I've done a simple script to iterate over the logs and compared each log size with a predefined value.
The problem is that that a logic condition is evaluated strangely, always evaluating TRUE.. can anybody help me understand why?
This is the script:
Const iAppMax = 2000000
Const iSecMax = 1000000
Const iSysMax = 100000
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTEventLogFile")
For Each objLogFile in colLogFiles
iLogMax = 0
Select Case objLogFile.LogFileName
Case "Application"
iLogMax = iAppMax
Case "Security"
iLogMax = iSecMax
Case "System"
iLogMax = iSysMax
End Select
If iLogMax > 0 And objLogFile.FileSize > iLogMax Then
WScript.Echo objLogFile.LogFileName & " is too big! Size = [" & objLogFile.FileSize & "]"
End If
Next On my system, the Application log is ~192KB, Security log is ~64 KB and System log is ~512 KB, making the output of the script to be:
Application is too big! Size = [196608]
Security is too big! Size = [65536]
System is too big! Size = [524288]
The problem is the second member of the If condition: oLogFile.FileSize > iLogMax which always evaluates TRUE (196608 > 2000000, 65536 > 1000000, 524288 > 100000), but it should be true just for the last one (System log, which is indeed bigger then 100000 bits).
Replacing the iLogMax variable with a plain numeric value, makes the script to run as supposed.
Why does this strange behavior occur?
Thanks