Run a command, trap the success/failure, and write an event

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

Hi folks,

I'm trying to write a simple VBScript to run a command,
and then write a system event log depending on if the
command ran sucessfully or if it failed, accordingly.

Can someone tell me how to do that?

Thanks,
Craig
 
On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
strDriveHarasty = "Z:"
strDriveMorestaff = "Y:"

WshNetwork.MapNetworkDrive strDriveHarasty, "\\Server5\Share"
ReportErrors "Mapping Drive."
WshNetwork.MapNetworkDrive strDriveMorestaff, "\\Server5\Share"
ReportErrors "Mapping Drive."

WshNetwork.AddWindowsPrinterConnection "\\davidcan\HP Laser Jet 6L"
ReportErrors "Adding Printer."
WshNetwork.SetDefaultPrinter "\\h8\HP Laser Jet 6L"
ReportErrors "Setting Default Printer."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveTimeOut", "209"
ReportErrors "Setting Screen Save SS Timeout Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveActive", "1"
ReportErrors "Setting Screen Save SS Active Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveIsSecure", "1"
ReportErrors "Setting Screen Save IsSecure Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSave.Exe", "F:\\WINNT\\System32\\ssmarque.scr"
ReportErrors "Setting Screen Save Scrnsave exe Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\BackgroundColor", "0 128 128"
ReportErrors "Setting Screen Save BackgroundColor Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Font", "Times New Roman"
ReportErrors "Setting Screen Save Font Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Mode", "1"
ReportErrors "Setting Screen Save Mode Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Size", "72"
ReportErrors "Setting Screen Save Size Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\TextColor", "192 192 192"
ReportErrors "Setting Screen Save TextColor Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Attributes", "00001"
ReportErrors "Setting Screen Save Attribute Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Speed", "8"
ReportErrors "Setting Screen Speed Text Failed."

WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Text", "M O R E S T A F F"
ReportErrors "Setting Screen Save Text (Morestaff) Failed."
WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\Text","H A R A S T Y S"
ReportErrors "Setting Screen Save Text (Harastys) Failed."

Sub ReportErrors(ErrText)
If err.number <> 0 then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.LogEvent 1, ErrText & " Error code " & err.number & " (" & err.description & ")"
Err.clear
End If
End Sub
 
Craig said:
I'm trying to write a simple VBScript to run a command, and then write a
system event log depending on if the command ran sucessfully or if it
failed, accordingly.

Can someone tell me how to do that?

Yes, but you're asking in the wrong group. Try .scripting.wsh.

To start, I recommend downloading the WSH documentation from the MS web
site. Look up the Run and LogEvent methods.

HTH,

Bill
 
Bill Stewart said:
Yes, but you're asking in the wrong group. Try .scripting.wsh.

You don't need VBScript:

dir x > nul
if errorlevel 1 eventcreate /l application /so dir /t information^
id 999 /d "x not found" & goto end
eventcreate /l application /so dir /t information /id 111^
/d "x found" & goto end
:end

At least if you are running XP Pro
 
Back
Top