|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Convert timegenerated format
I was wondering if its possible to convert TimeGenerated output into more readable format?
Thanks [code] objTextFile.WriteLine("Event Number: " & LogEvent.RecordNumber & chr(13)) objTextFile.WriteLine("Log File: " & LogEvent.LogFile & chr(13)) objTextFile.WriteLine("Type: " & LogEvent.Type & chr(13)) objTextFile.WriteLine("Message: " & LogEvent.Message & chr(13)) objTextFile.WriteLine("Time: " & LogEvent.TimeGenerated & chr(13)) [code] |
|
#2
|
||||||||
|
||||||||
|
You haven't provided enough information to determine what the LogEvent object is, so I'm going out on a limb here and assuming this is the object returned by the WMI Win32_NTLogEvent class.
The DateTime format used by WMI (CIM_DATETIME) is essentially nothing more than a string containing the various date and time parts for a given point in time (or an interval). So you can parse the string to find the relevant date and time pieced and use VBScript's serial functions to construct a VBScript Date value (VT_DATE). This can be accomplished with a simple function as seen below. vb Code:
vb Code:
__________________
Scripting problems? Windows questions? Ask the Windows Guru! Stay up to date with all of my latest content. Follow me on Twitter! Help us help you! Post your exact error message with these easy tips! Last edited by Nilpo : September 30th, 2009 at 02:09 AM. |
|
#3
|
|||
|
|||
|
Thanks.
Thats great. I incorporated the second example and it outputted nice date format. cheers. Code:
' Create a new datetime object.
Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")
dim sMessage
Set EventSet = GetObject("winmgmts:").ExecQuery("select * from Win32_NTLogEvent where EventCode=" & iEventCode)
if (EventSet.Count = 0) then WScript.Echo "No Events"
for each LogEvent in EventSet
objTextFile.WriteLine("Event Number: " & LogEvent.RecordNumber & chr(13))
objTextFile.WriteLine("Log File: " & LogEvent.LogFile & chr(13))
objTextFile.WriteLine("Type: " & LogEvent.Type & chr(13))
objTextFile.WriteLine("Message: " & LogEvent.Message & chr(13))
objDateTime.Value = LogEvent.TimeGenerated
objTextFile.WriteLine("Time: " & objDateTime.GetVarDate & chr(13))
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Convert timegenerated format |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|