 |
| VBScript For questions and discussions related to VBScript. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 30th, 2004, 02:13 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Source name in LogEvent
I am trying to write an event to eventlog using Vbscript. I am using WshShell 's LogEvent. I need to set the source name, how can i do that. Eg will be most helpful.
Thanks in advance.
|

December 30th, 2004, 08:58 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Hi,
You can't do this from VBScript per se since any event you generate in vbscript will show WSH as the source, like this:
'===============================
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.LogEvent 0, "MyFile.vbs by mmcdonal"
'===============================
This creates an event in the event log with the event number of 0 with the text as the description and the source "WSH".
You can call CMD.EXE from your script and use the "Eventcreate" command, however. Here is some syntax...
'=========================================
C:\>eventcreate /l Application /t Information /so Me /id 100 /d Test
'=========================================
This code creates an event log in the Application log, with the Type "Information", the Source "Me", an Event Number of 100 (must be 1 - 1000) and the Description "Test"
Go to the command prompt and type eventcreate /? for all the available switches. I can't remember how to call CMD right now, so I didn't put that part in. Can someone else help with that?
I hope this helps.
mmcdonal
|

January 3rd, 2005, 02:36 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Again,
Aah, EventCreate is exclusively for windows XP and above versions. Is there a way to create event for lower versions of windows, (windows 2000 server) onwards??
Kindly help...
Regards.
|

January 7th, 2005, 10:56 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Well, maybe there is another way around this. Do you need to have a particular source name so that you can parse the event logs with another script, or for searching the logs visually/manually?
If you are using another script, you don't need the source name because you can use other features of the event to identify the one you are looking for with the script. If it is visually, then just look for WSH as the source, and then set an odd event number like "999."
I hope this helps.
mmcdonal
|

January 11th, 2005, 01:38 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, I need to put my application name as source and the entry in the event log should be made without interacting with any dll as such. I have found a another way altogether to do this using RegisterEventlog() etc.
I have had started with WSH, but its not confined to my app name, so i was looking for some help.
Thanks a lot for your help, mmcdonal.
|

January 27th, 2005, 10:18 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi startfish,
I'm facing the exact same problem of creating event logs using WSH. Would you mind sharing your experiences using RegisterEventlog() you mentioned??
Thank you in advance!!
|

January 12th, 2011, 02:46 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This article helped to steer me on the write path so I wanted to let everyone know how I went about doing this. I am searching a text file for errors and if I find one, I wanted to write a custom event to the event viewer with a custom source and custom ID number.
Code:
'## write the custom event to event viewer - chr34 is inserting quote within quote
CmdLine = "eventcreate /l Application /t ERROR /so ERS /id 100 /d " & chr(34) & ErrorMessage[this is another variable i defined earlier] &_
". Please contact ERS technical to resolve" & chr(34)
objWSHShell.Run CmdLine
This creates an error event in the event viewer with a source of ERS and an event ID of 100 with my custom error message. mmcdonal's post above is very helpful. Hope this helps
Last edited by thedude; January 12th, 2011 at 02:48 PM..
|
|
 |