Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

12Sep/090
How to Write to the Windows Application Log Using VBScript

This script helped me configure an enterprise monitoring system. I created little events in the Windows event log and monitored the events using the syslog system we implemented. The script creates any id and description you need.

Const EVENT_SUCCESS = 1

Set objShell = Wscript.CreateObject("Wscript.Shell")

objShell.LogEvent EVENT_SUCCESS, "Test error."

WScript.Echo "Complete"
25May/091
Output the Date in a Windows Batch Script

This simple script will output the date in the MMDDYYYY format. The script can be used to enhance other scripts, for log files, etc.

@echo off
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
@REM The date variable will be in the MMDDYYYY format so it can be called later in the script

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%

@echo on
echo hello %date%
pause
16Jan/090
Read Each Line of a File with VBScript

A very useful script that will read each line of a text file and output the results. I use this for everything from reading log files and parsing the results to searching files for error messages.

Option Explicit
Dim objFile, strLine
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile= objFSO.OpenTextFile("C:\textfile.txt", 1)
Do While Not objFile.AtEndOfStream
	strLine = objFile.readline
	WScript.Echo strLine
Loop
objFile.Close