Collect Item Return in diffrent order.  
Author Message
JamesCool





PostPosted: Tue Jan 18 14:23:04 CST 2005 Top

VB Scripts >> Collect Item Return in diffrent order. Hello all,

I'm not the best programer in the world so I was wondering if I could get a
little help from you all. I'm using VBScript to make a WMI call to the event
viewer on a 2003 server. The return for the query is great... Code snip.

et colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
WHERE (Logfile = 'System') AND (EventCode = '6005'or EventCode = '6008' or
EventCode = '1074' or EventCode = '1076') AND (SourceName <> 'W3SVC')")

intCount = 0
For Each objService in ColEvents

if objService.EventCode = "6005" THEN
strboottime = objService.Timewritten
end if

if objService.EventCode = "1074" THEN
intCount = intCount + 1
strstoptime = objService.Timewritten
strdiff = ( DateDiff("s", WMIDateStringToDate(strstoptime),
WMIDateStringToDate(strboottime)) )
intdiff = intdiff + strdiff
WScript.Echo "Down For: " & SecondsToText(strdiff)

This returns....

Down For: 1 Minute, 7 Seconds
Down For: 1 Minute, 24 Seconds
Uptime Report For: CSCS-IT-007C
Microsoft Windows XP Professional 5.1.2600
Install Date: 12/06/2004 11:28:17
Last Reboot: 01/11/2005 18:03:23
Up For: 6 Days, 17 Hours, 45 Minutes, 9 Seconds
Total Reboots: 2
Total Down Time: 2 Minutes, 31 Seconds

So far so good, now I want to change how far back data is collection so I
mode the query to look for timewritten... code snip...

Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date - 365
dtmStartDate.SetVarDate DateToCheck, True

Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
dtmEndDate.SetVarDate Date, True
WScript.Echo "Start Date: " & dtmStartDate & " End Date: " & dtmEndDate


Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
WHERE TimeWritten >= '"&dtmStartDate&"' AND Logfile = 'System' AND (EventCode
= '6005'or EventCode = '6008' or EventCode = '1074') AND SourceName <>
'W3SVC'")


The problem I have is the output order is diffrent. Instead of DESC it now
AESC. I have tried to add ORDER BY TimeWritten but I get an error. Any
insite on how to change the order would be very helpfull.

Thanks
David.

Visual Studio162  
 
 
FreRange





PostPosted: Tue Jan 18 14:23:04 CST 2005 Top

VB Scripts >> Collect Item Return in diffrent order. Anothe note on this script.. I also tried to change this bit of code for the
date.... But it still returns events that are older the 365 days.

For Each objService in ColEvents

if objService.EventCode = "6005" [new here] AND objservice.TimeWritten >=
dtmStartDate THEN
strboottime = objService.Timewritten
strlastboot = WMIDateStringToDate(strboottime)
end if

if objService.EventCode = "1074" THEN
intCount = intCount + 1
strstoptime = objService.Timewritten
strdiff = ( DateDiff("s", WMIDateStringToDate(strstoptime),
WMIDateStringToDate(strboottime)) )
intdiff = intdiff + strdiff
WScript.Echo "Down For: " & SecondsToText(strdiff) & " On " &
WMIDateStringToDate(strstoptime)
end if

"FreRange" wrote:

> Hello all,
>
> I'm not the best programer in the world so I was wondering if I could get a
> little help from you all. I'm using VBScript to make a WMI call to the event
> viewer on a 2003 server. The return for the query is great... Code snip.
>
> et colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
> WHERE (Logfile = 'System') AND (EventCode = '6005'or EventCode = '6008' or
> EventCode = '1074' or EventCode = '1076') AND (SourceName <> 'W3SVC')")
>
> intCount = 0
> For Each objService in ColEvents
>
> if objService.EventCode = "6005" THEN
> strboottime = objService.Timewritten
> end if
>
> if objService.EventCode = "1074" THEN
> intCount = intCount + 1
> strstoptime = objService.Timewritten
> strdiff = ( DateDiff("s", WMIDateStringToDate(strstoptime),
> WMIDateStringToDate(strboottime)) )
> intdiff = intdiff + strdiff
> WScript.Echo "Down For: " & SecondsToText(strdiff)
>
> This returns....
>
> Down For: 1 Minute, 7 Seconds
> Down For: 1 Minute, 24 Seconds
> Uptime Report For: CSCS-IT-007C
> Microsoft Windows XP Professional 5.1.2600
> Install Date: 12/06/2004 11:28:17
> Last Reboot: 01/11/2005 18:03:23
> Up For: 6 Days, 17 Hours, 45 Minutes, 9 Seconds
> Total Reboots: 2
> Total Down Time: 2 Minutes, 31 Seconds
>
> So far so good, now I want to change how far back data is collection so I
> mode the query to look for timewritten... code snip...
>
> Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
> DateToCheck = Date - 365
> dtmStartDate.SetVarDate DateToCheck, True
>
> Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
> dtmEndDate.SetVarDate Date, True
> WScript.Echo "Start Date: " & dtmStartDate & " End Date: " & dtmEndDate
>
>
> Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
> WHERE TimeWritten >= '"&dtmStartDate&"' AND Logfile = 'System' AND (EventCode
> = '6005'or EventCode = '6008' or EventCode = '1074') AND SourceName <>
> 'W3SVC'")
>
>
> The problem I have is the output order is diffrent. Instead of DESC it now
> AESC. I have tried to add ORDER BY TimeWritten but I get an error. Any
> insite on how to change the order would be very helpfull.
>
> Thanks
> David.
>
>
>
 
 
FreRange





PostPosted: Wed Jan 19 17:41:59 CST 2005 Top

VB Scripts >> Collect Item Return in diffrent order. Hello? Anyone out there *grin*. I know that I have an odd question but I
was hoping that I gave you all enough information to lead me in the right
direction....

Thanks
David.

"FreRange" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Anothe note on this script.. I also tried to change this bit of code for
> the
> date.... But it still returns events that are older the 365 days.
>
> For Each objService in ColEvents
>
> if objService.EventCode = "6005" [new here] AND objservice.TimeWritten >=
> dtmStartDate THEN
> strboottime = objService.Timewritten
> strlastboot = WMIDateStringToDate(strboottime)
> end if
>
> if objService.EventCode = "1074" THEN
> intCount = intCount + 1
> strstoptime = objService.Timewritten
> strdiff = ( DateDiff("s", WMIDateStringToDate(strstoptime),
> WMIDateStringToDate(strboottime)) )
> intdiff = intdiff + strdiff
> WScript.Echo "Down For: " & SecondsToText(strdiff) & " On " &
> WMIDateStringToDate(strstoptime)
> end if
>
> "FreRange" wrote:
>
>> Hello all,
>>
>> I'm not the best programer in the world so I was wondering if I could get
>> a
>> little help from you all. I'm using VBScript to make a WMI call to the
>> event
>> viewer on a 2003 server. The return for the query is great... Code
>> snip.
>>
>> et colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
>> WHERE (Logfile = 'System') AND (EventCode = '6005'or EventCode = '6008'
>> or
>> EventCode = '1074' or EventCode = '1076') AND (SourceName <> 'W3SVC')")
>>
>> intCount = 0
>> For Each objService in ColEvents
>>
>> if objService.EventCode = "6005" THEN
>> strboottime = objService.Timewritten
>> end if
>>
>> if objService.EventCode = "1074" THEN
>> intCount = intCount + 1
>> strstoptime = objService.Timewritten
>> strdiff = ( DateDiff("s", WMIDateStringToDate(strstoptime),
>> WMIDateStringToDate(strboottime)) )
>> intdiff = intdiff + strdiff
>> WScript.Echo "Down For: " & SecondsToText(strdiff)
>>
>> This returns....
>>
>> Down For: 1 Minute, 7 Seconds
>> Down For: 1 Minute, 24 Seconds
>> Uptime Report For: CSCS-IT-007C
>> Microsoft Windows XP Professional 5.1.2600
>> Install Date: 12/06/2004 11:28:17
>> Last Reboot: 01/11/2005 18:03:23
>> Up For: 6 Days, 17 Hours, 45 Minutes, 9 Seconds
>> Total Reboots: 2
>> Total Down Time: 2 Minutes, 31 Seconds
>>
>> So far so good, now I want to change how far back data is collection so I
>> mode the query to look for timewritten... code snip...
>>
>> Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
>> DateToCheck = Date - 365
>> dtmStartDate.SetVarDate DateToCheck, True
>>
>> Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
>> dtmEndDate.SetVarDate Date, True
>> WScript.Echo "Start Date: " & dtmStartDate & " End Date: " & dtmEndDate
>>
>>
>> Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent
>> WHERE TimeWritten >= '"&dtmStartDate&"' AND Logfile = 'System' AND
>> (EventCode
>> = '6005'or EventCode = '6008' or EventCode = '1074') AND SourceName <>
>> 'W3SVC'")
>>
>>
>> The problem I have is the output order is diffrent. Instead of DESC it
>> now
>> AESC. I have tried to add ORDER BY TimeWritten but I get an error. Any
>> insite on how to change the order would be very helpfull.
>>
>> Thanks
>> David.
>>
>>
>>