Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 29th, 2009, 09:43 AM
duxbuz duxbuz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 12 duxbuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 43 sec
Reputation Power: 0
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]

Reply With Quote
  #2  
Old September 30th, 2009, 02:06 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,880 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 47 m 8 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
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:
Original - vb Code
  1. Private Function WMItoVBTime(strDateTime)
  2.     strYear  = Mid(strDateTime,  1, 4)  ' 4-digit years
  3.     strMonth = Mid(strDateTime,  5, 2)  ' 2-digit months
  4.     strDay   = Mid(strDateTime,  7, 2)  ' 2-digit days
  5.     strHour  = Mid(strDateTime,  9, 2)  ' 2-digit hours
  6.     strMin   = Mid(strDateTime, 11, 2)  ' 2-digit minutes
  7.     strSec   = Mid(strDateTime, 13, 2)  ' 2-digit seconds
  8.  
  9.     WMItoVBTime = DateSerial (strYear, strMonth, strDay) & " "TimeSerial (strHour, strMin, strSec)
  10. End Function
WMI also provides its own intrinsic method of converting date and time values using the SWbemDateTime Object.
vb Code:
Original - vb Code
  1. ' Create a new datetime object.
  2. Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")
  3.  
  4. ' Retrieve a WMI object that contains a datetime value.
  5. For Each objOS In GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
  6.     ' The InstallDate property is a CIM_DATETIME.
  7.     objDateTime.Value = objOS.InstallDate
  8.  
  9.     ' Display the installation date using the VT_DATE format.
  10.     MsgBox objDateTime.GetVarDate
  11. Next
__________________
Don't like me? Click it.

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.

Reply With Quote
  #3  
Old September 30th, 2009, 04:06 AM
duxbuz duxbuz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 12 duxbuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 43 sec
Reputation Power: 0
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))

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > Convert timegenerated format


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek