I am not sure if I am so exhausted, that I don't find anything wrong with this though it runs fine from command prompt using cscript, still it is playing with my time by not creating the job giving this error.
Error 14277: The command script does not destroy all the objects that it creates. Revise the command script. The job was not saved.
I have similar other steps with vbscripts working fine. But still this kills my time. Can anyone see if I am doing something wrong with this code.
This script basically starts an application and verifies if its child processes are running fine, else sends out an email with error.
The ones in BLUE are the objects created, and the ones
BLUE are the objects destroyed.
Code:
Dim StrComputer, StrSql, Con, ConStr, RS, objWMIService, colProcessList, iRow, iCol, ArrRowSet
Dim Wshshell, StrCmd, RetCode
StrComputer = "."
Set Con = CreateObject("adodb.connection")
ConStr = "Provider=sqloledb;Data Source=localhost;Initial Catalog=SOMEDB;User Id=xyz;Password=xyz;"
Con.Open ConStr
StrSql = "SELECT AppName FROM mytable ORDER BY StartupSeqID"
Set RS = Con.Execute(StrSql)
ArrRowSet = RS.GetRows()
Set Con = Nothing
Set RS = Nothing
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
Set Wshshell = WScript.CreateObject("wscript.shell")
StrCmd = """C:\Program Files\someapp.exe"""
RetCode = Wshshell.run(StrCmd, 1, FALSE)
WScript.Sleep(5000)
If RetCode = 0 Then
'Verify the relevant child processes of this app
For iRow = LBound(ArrRowSet, 2) To UBound(ArrRowSet, 2)
For iCol = LBound(ArrRowSet, 1) To UBound(ArrRowSet, 1)
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & ArrRowSet(iCol, iRow) & "'")
For Each objProcess in colProcessList
If UCase(objProcess.Name) <> UCase(ArrRowSet(iCol, iRow)) Then
SendErrorMail ArrRowSet(iCol, iRow)
End If
Next
Set colProcessList = Nothing
Next
Next
End If
Set objWMIService = Nothing
Set Wshshell = Nothing
Function SendErrorMail (strAppName)
Dim objNet, objCDOMail, strBody, strTo, strSubject, strCC, strComputerName
strTo = "me@myid.com"
Set objNet = CreateObject("WScript.NetWork")
strComputerName = objNet.ComputerName
Set objNet = Nothing
strSubject = "some subject"
strBody = strBody & "some body message"
Set objCDOMail = CreateObject("CDO.Message")
objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOMail.Configuration.Fields.Update
objCDOMail.From = strComputerName
objCDOMail.To = strTo
objCDOMail.CC = strCC
objCDOMail.Bcc = strBcc
objCDOMail.Subject = strSubject
objCDOMail.TextBody = strBody
objCDOMail.Send
Set objCDOMail = Nothing
End Function
Cheers.
_________________________
- Vijay G
Strive for Perfection