Process question

Is there a way to trap an event relating to trying to start a process when the computer lacks the application.  For instance doing a process.start on a MS Project file when the computer lacks the application.  Now my application just hangs when that occurs.

Thanks,
Fred


Answer this question

Process question

  • d.v.d

    I'm assuming you are not using "ProcessStartInfo" take alook there are several methods and properties to handle non-start errors such as:

    Public Property ErrorDialogParentHandle() As
    System.IntPtr

    Member of: System.Diagnostics.ProcessStartInfo

    Summary:

    Gets or sets the window handle to use when an error dialog is shown for a process that cannot be started.

    and

    Public Property ErrorDialog() As Boolean

    Member of: System.Diagnostics.ProcessStartInfo

    Summary:

    Gets or sets a value indicating whether an error dialog is displayed to the user if the process cannot be started.



  • Hitesh Shah

    I thought I might be easier to repose my question about process.start with my code.  I have embedded my start event in a try/catch.  In this example I am trying to launch MS Project and open a .mpp file.  Unformtunately the computer does not have the application installled.  Instead of raising an exception, the application hangs.  I would like to know either how to trap the error or determine via software if the client computer has the target application installed.

    Thanks,
    Fred

     

    Private Sub LoadProject(ByVal selectedRow As DataRow)
            Dim DataType As String = "Project"
            Dim BLOB() As Byte

            'Load the encrypted encryped file  from the server
            Try
                If CInt(selectedRow("Project")) = 1 Then
                    BLOB = LoadBLOBData(DataType, CStr(selectedRow("ID")))
                Else
                    Exit Sub
                End If
            Catch MyException As Exception
                StatusMessage.Clear()
                StatusMessage.Text = "Error on documnet load due to: " & MyException.message
                Exit Sub
            End Try

            'Create a process and display the document
            Try
                Dim filepath As String = "c:\program files\ApplicationData.mpp"
                Dim fs As New FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write)
                fs.Write(BLOB, 0, CInt(BLOB.Length))
                fs.Close()
                XMainForm.Visible = False
                Dim proc As New System.Diagnostics.Process
                proc.StartInfo.UseShellExecute = True
                proc.StartInfo.FileName = filepath
                proc.Start()
                While Not proc.HasExited
                End While
                StatusMessage.Clear()
                StatusMessage.Text = "Application exited with exitcode: " + proc.ExitCode.ToString()
                proc.Dispose()
                XMainForm.Visible = True
            Catch MyException As Exception
                StatusMessage.Clear()
                StatusMessage.Text = "Unable display requested file due to: " & MyException.message
            End Try
        End Sub



  • Karv

    You could use com-interop to check if the application can be instantiated, rather than trying to start it as a seperate process. You can trap any errors in that code easily. Theres an example of using project com-interop and the Project Objectmodel here

    Cathal

  • Pacific Ocean Blue

    your app is hanging because of the never ending loop:


    While Not proc.HasExited
    End While

     


    Get rid of the loop and add



    proc.StartInfo.ErrorDialog = True

     


    so your code will look like this:



    Dim proc As New System.Diagnostics.Process
               proc.StartInfo.UseShellExecute = True
               proc.StartInfo.ErrorDialog = True
               proc.StartInfo.FileName = filepath
               if Not proc.Start() then
                ...
               end if

     


    Public Function Start() As Boolean

    Member of: System.Diagnostics.Process

    Summary:

    Starts (or reuses) the process resource that is specified by the System.Diagnostics.Process.StartInfo property of this System.Diagnostics.Process component and associates it with the component.

    Return Values:

    true if a process resource is started; false if no new process resource is started (for example, if an existing process is reused).

    Exceptions:

    System.ObjectDisposedException: The process object has already been disposed.

    System.ComponentModel.Win32Exception: There was an error in opening the associated file.

    System.InvalidOperationException: No file name was specified in the System.Diagnostics.Process component's System.Diagnostics.Process.StartInfo.-or- The System.Diagnostics.ProcessStartInfo.UseShellExecute member of the System.Diagnostics.Process.StartInfo property is true while System.Diagnostics.ProcessStartInfo.RedirectStandardInput, System.Diagnostics.ProcessStartInfo.RedirectStandardOutput, or System.Diagnostics.ProcessStartInfo.RedirectStandardError is true.



  • Process question