Folks, I'm working on an admin script that will look at a servers' scheduled tasks and verify that #1; it's enabled or disable; #2; alert if disabled; and #3; continue to monitor the sheduled tasks 24X7. So, I've created this script that is suppose to do this; however it's not working 100% and I'm actually fairly new to scripting so if anyone out there who is good a scripting can take a look, and let me know where I might be going wrong I'd greatly appreciate it!
Script:
Option Explicit
Dim CSV3, objFSO, objTextFile, strNextLine, arrServiceList, String3, i
Dim objshell, sCommand, systempath
Const ForReading = 1
Const EVENT_ERROR = 1
Set objshell = Wscript.Createobject("WScript.Shell")
systempath = objShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
sCommand = "cmd /C schtasks.exe /query /FO table /V >> C:\schedtaskmon.txt"
objshell.Run sCommand
'WScript.Sleep 1000
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\schedtaskmon.txt", ForReading)
'Skipping Header Row
objTextFile.SkipLine
objTextFile.SkipLine
objTextFile.SkipLine
Do Until objTextFile.AtEndOfStream
dim task, state
strNextLine = objTextFile.ReadLine
task = substring(strNextLine, 16,36)
task = Trim(task)
state = substring(strNextLine, 369, 28)
state = Trim(state)
If Not LCase(state) = "enabled" Then
'arrServiceList = Split(strNextLine , ",")
For i = 2 To Ubond(arrServiceList)
If arrServiceList(i) = """Disabled""" Then
WScript.Echo "Match"
objshell.LogEvent EVENT_ERROR, _
"Schedule Job: " & arrServiceList(0) & " Schedule process Disabled, please check scheduler."
End If
Next
Loop
Function substring(str, start, length)
dim s, rval
s = left(str, start+length)
rval = right (s, length)
substring = rval
end Function