We use a third-party app (CDL) that generally runs for 7+ hours while it compiles data. The people who use the CDL have about a 50-ish step program that they have to do manually and simple mistakes can crash the data build. I am writing a little app to automate the steps and to incorporate data integrity.
The problem I am having is when the CDL is called, if a critical file is missing (or other problem), the CDL will display the error in a message box. There are too many things to check for (server down, server process not running, user issues). The biggest issue can occur at the very start of the CDL, so this is the main thing that I check for.
My problem is that I need a way to check to see if the message box is being displayed, so I can then kill the process and flag an alert for user intervention.
I tried printing out a list of all open windows, but the message box's title does not appear in the list.
For Each p As Process In Process.GetProcesses
Debug.Print(p.MainWindowTitle)
Debug.Print("-------------------------------")
Next
So, Im looking to see if anyone has any suggestions or can point me in the right direction. If I can detect an error notification, then I can kill the process and alert the user. It would even be nice to be able to extract text from the message box so that I can possibly fix an error programatically.
I am writing the app in vb.NET, and the CDL program is written in Java (this is where the error msg originates). If I can detect the msgbox via code, should I be looking at the OS services running? or somewhere else.
The problem I am having is when the CDL is called, if a critical file is missing (or other problem), the CDL will display the error in a message box. There are too many things to check for (server down, server process not running, user issues). The biggest issue can occur at the very start of the CDL, so this is the main thing that I check for.
My problem is that I need a way to check to see if the message box is being displayed, so I can then kill the process and flag an alert for user intervention.
I tried printing out a list of all open windows, but the message box's title does not appear in the list.
For Each p As Process In Process.GetProcesses
Debug.Print(p.MainWindowTitle)
Debug.Print("-------------------------------")
Next
So, Im looking to see if anyone has any suggestions or can point me in the right direction. If I can detect an error notification, then I can kill the process and alert the user. It would even be nice to be able to extract text from the message box so that I can possibly fix an error programatically.
I am writing the app in vb.NET, and the CDL program is written in Java (this is where the error msg originates). If I can detect the msgbox via code, should I be looking at the OS services running? or somewhere else.
Code:
Private Sub RunCDL()
Dim msg As String = ""
Dim hdr As String = ""
Dim cdlFullPath As String = dflt.PathCDL & cdlFilename
Dim rdr As StreamReader
Dim line As String
Dim idx As Integer
Dim fJavaPathNotFound As Boolean = False
Dim pCDL As New Process() 'Create a new process to run the CDL
Dim pCDL_Info As New ProcessStartInfo(cdlFullPath)
Try
'Make sure batch file exists
If Not ValidateFilename(cdlFullPath) Then
msg = String.Format("Could not find the batch file ({0}) in the " & _
"specified folder: {1}", cdlFilename, dflt.PathCDL)
hdr = String.Format("ERROR! BATCH FILE NOT FOUND! ({0})", Now)
Throw New UserClasses.UserInputErrors
End If
'The following two values must be set to prevent
' an InvalidOperationException error
pCDL_Info.UseShellExecute = False
pCDL_Info.RedirectStandardError = True
pCDL.StartInfo = pCDL_Info
pCDL.Start()
'Sleep five seconds to give batch file time to start
Sleep(5000)
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle.Length > 0 Then
If p.MainWindowTitle.ToString = "CDL" Then
pCDL.Kill()
End If
End If
Next p
Catch ex As UserInputErrors
UserClasses.UserInputErrors.MsgErrTitle = hdr
Throw New UserClasses.UserInputErrors(msg)
Finally
pCDL.Close()
pCDL.Dispose()
End Try
End Sub 'RunCDL