Batch, vbscript to start/end process

This question is not programming related, but to go around to resolve the problem by batch or vbscript to start/end process.

I have a very old custom application which is not updated anymore. It checks XML file at remote site every 5 minutes. I need to make sure it runs all the time. Recently we have an issue it throws 'Run Time' error.

When I look at the log, it says 'Invalid Argument' then the process throws the error.

Is there a way for any script to contiguously monitor this log and if it encounters 'invalid argument', then it forces to end the process and restart? After the application is restarted, it doesn't require user interaction such as clicking button or any.
LVL 1
crcsupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Can you post an example of the log file?
0
Bill PrewCommented:
Agreed, it would be best to figure out what is causing the error and try to eliminate that.  But if that's not possible...

Are you sure the process doesn't end when it throws the error?  If that were the case, then you could just check every few minutes if the process is still running, and if not restart it.

Of course you could write a BAT or VBS script that looks for the log file, and if found with the error, deletes the log file, and stops and restarts the process.  That would not be that hard in BAT.  You could then schedule that to run on some frequency from Windows Task Scheduler and it could check each time it runs.

To create the batch script I would need some additional info, like where will the log file be located, and example of it's format, including the error message, what the process name and info is, how to restart it, etc.

~bp
0
crcsupportAuthor Commented:
As I said, The software developer is not available to source code to fix this. Also, I thought this is caused by the XML data provider to the application, but the company denies any change made to the xml data format, which I strongly believe, but contacted 3 times, seem as they are rock hard on saying no change. .
Anyway, the option is I have to have script runs on background to check the below string in the log every 5 minutes or more and stop/start the aplication (abc.exe).

log
===================
GetFlightDetails>>3001 - At line [3390] Invalid argument.
=============================================
As soon as it writes this string line, the application stops showing 'Runtime 3390' with popup. Then it stops working. So I normally click 'OK', then restart the abc.exe application. The flow of doing this automatically is

1. background script checks the log file with '[3390] Invalid argument' every 5 minute, if there is, force to close abc.exe process.
2. Then restart abc.exe

I got a few examples of scripts to terminate process. I think I can just reuse them modifying it. But can you give me some idea or example of codes which will run all the time and check line string in log file every x minute?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

sirbountyCommented:
I would suggest using an __InstanceModificationEvent (http://msdn.microsoft.com/en-us/library/aa394651.aspx)

http://stackoverflow.com/questions/10041057/how-to-monitoring-folder-files-by-vbs gives an example script on how to do this.  It will 'watch' a folder, based on a value every n seconds.  You can filter based on the file name of the log file.  That would tell you that the log was changed.  You would just need to go through the log to find that text string.  Since you haven't posted a sample log, I can't really help much further than that.
The scripting guy has a good example on how to do this... http://blogs.technet.com/b/heyscriptingguy/archive/2007/03/29/how-can-i-search-a-text-file-for-strings-meeting-a-specified-pattern.aspx
0
crcsupportAuthor Commented:
Thanks for the link. I also posted here, the log file and screen shot of the log folder structure. Basically once it encounters "3001 - At line [3390] Invalid argument.", it stops logging in the log file and creates another logfile with date.

log folderlogfile.txt
0
sirbountyCommented:
Repurposing some of those scripts already posted, something like this could work:
If as stated in the code comments, you simply need to watch for the file creation (sounds like it from your description above), then you could fire the RecycleProcess sub at that point (that sub needs to be adjusted with your process name/location, as well as the log path on the first line...

sPath = "C:\logs\"
sComputer = "."
sDrive = Left(sPath,2)
sFolders = REPLACE(sPath, "\", "\\")

Set objWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE " _
& "TargetInstance ISA 'CIM_DataFile' AND " _
& "TargetInstance.Drive='" & sDrive & "' AND " _
& "TargetInstance.Path='" & sFolders & "' AND " _
& "TargetInstance.Extension = 'log' ")

Wscript.Echo vbCrlf & Now & vbTab & _
"Begin Monitoring for " & sPath & "'s Change Event..." & vbCrlf

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Select Case objLatestEvent.Path_.Class

    Case "__InstanceCreationEvent"
    'TODO:  Based on your description, if simply hitting the error triggers a new
	'log file, you could trap for this event, and perform your process recycle
    'RecycleProcess

    'WScript.Echo Now & vbTab & objLatestEvent.TargetInstance.FileName & "." & objLatestEvent.TargetInstance.Extension _
    '& " was created" & vbCrlf

    'Case "__InstanceDeletionEvent"
    'WScript.Echo Now & vbTab & objLatestEvent.TargetInstance.FileName & "." & objLatestEvent.TargetInstance.Extension _
    '& " was deleted" & vbCrlf

    Case "__InstanceModificationEvent"
    'Otherwise, you'd need to open the file, check for the error, and then perform the process recycle
    If objLatestEvent.TargetInstance.LastModified <> _
    objLatestEvent.PreviousInstance.LastModified then
    WScript.Echo Now & vbTab & objLatestEvent.TargetInstance.FileName & "." & objLatestEvent.TargetInstance.Extension _
    & " was modified" & vbCrlf
    End If
    End Select
Loop

Set objWMIService = nothing
Set colMonitoredEvents = nothing
Set objLatestEvent = nothing

Sub RecycleProcess
  Dim objShell : Set objShell = CreateObject ("Wscript.Shell")
  objShell.Run "taskkill /im MyApplication.exe /f"
  wscript.sleep 1000
  objShell.Run "start c:\Folder\MyApplication.exe"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crcsupportAuthor Commented:
Thanks all. This is enough for me to start.
0
sirbountyCommented:
Happy to help - thanks for the grade! :^)
0
Bill PrewCommented:
Thanks for the feedback.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.