tags:

views:

13

answers:

0

Hi Folks,

I am trying to write to the Windows Event Log (Win2k8 R2) from vbs.

I am a complete novice to vbs by the way!

I have a script that I am running that does xyx and I want to put some logging in there.

Script:

' VBScript source code
 Option Explicit

 HostInstanceFailover
 Sub HostInstanceFailover()
WScript.Echo "Entering HostFailover script."
'Get the command line arguments entered for the script
Dim Args: Set Args = WScript.Arguments

'error handling is done by explicity checking the err object rather than using
'the VB ON ERROR construct, so set to resume next on error.
On Error Resume Next

etc...

I tried to use the following code in there and it fails complaining about the WshShell Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.LogEvent 0, "Logon Script Completed Successfully"

http://msdn.microsoft.com/en-us/library/b4ce6by3

but if I run the code off the msdn site on its own it works fine...

I must have the syntax wrong or something?

MyCode:

Sub WriteEventLog()
  Set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.LogEvent 0, "Logon Script Completed Successfully"
End Sub

Thanks in advance!

Cheers