Avatar of Steve Williams
Steve Williams
Flag for United States of America

asked on 

Why does System.Diagnostics.Process.Start open file with errors?

Ok So I write this app to quickly find files in a source directory and all its sub directories. The search and find portion works great. The files that this app searches for are used for laser etching part numbers on our products. We have roughly 20,000+ product configurations available in the sub directories. The vb app I wrote has two major functions aside from the search and find, these include Edit & Burn. Each function requires a different .exe to complete the task. Here is a follow thru on how the app should work:
The user types a part number to search for an etching pattern to burn
The user now checks a radio button to choose a task either edit or burn
Then the user can either tab to and use the arrow keys and hit enter or double click the selected item in the list box to open the file
If the edit is chosen the edit software opens up the file and they make their changes, saves their work and then closes the edit application.
Either after they edit the file or just initially choose the burn radio button, the user can either tab to and use the arrow keys and hit enter or double click the selected item in the list box to open the file.
The user can now use the burn application to mark the products for the current order.
Then they can close the burn application and the next order is ready for the Etch-O-Matic application.


Due to licensing the installed editing and burn  software is only allowed to be installed on one computer with the required usb dongle. For this reason I created some blank ".vlm" files and sub directories to test the app on my development computer. I also use MS Excel 2016 for the edit program and MS Word 2016 for the burn program just to test functionality of the vb code.

Now the issues! When I open the file for edit or burn an error comes up saying it can't find the file "C:\Program.xlsx" for edit and "C:\Program.doc" for burn. Then the file does not open. Then I get a couple other errors. See the attached images for the errors that come up.

The development computer is running Windows 10 Professional and am using VB Community 2015 to write the code. The Laser Etching machine is running Windows XP SP3 with dot net 4.0.

Not sure if any of this makes sense or if any of you have heard of these errors before. I searched for fixes for all of the errors and I get nothing. I also tried to see if there was another way of opening the files other than using the System.Diagnostics.Process.Start.

Here is the code for the form frmEtchOMatic.vb
Imports System.IO
Imports System.ComponentModel
Imports System.Threading
Imports System.Diagnostics

Public Class frmEtchOMatic

    Private Const SourceFolder As String = "C:\Program Files\VisualLaserMarker\MarkingFiles"
    Private _bsFiles As New BindingSource()
    Private _dtFiles As New DataTable()

    Private Sub frmEtchOMatic_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not Directory.Exists(SourceFolder) Then Throw New Exception("Folder doesn't exist")
        _dtFiles.Columns.Add("FilePath")
        _dtFiles.Columns.Add("FileName")

        RefreshFiles()

        _bsFiles.DataSource = _dtFiles
        lstPartNum.DisplayMember = "FileName"
        lstPartNum.ValueMember = "FilePath"
        lstPartNum.DataSource = _bsFiles
        Me.Show()
        txtPartNum.Focus()
        Me.Text = "Etch-O-Matic  " & String.Format("Version {0}", My.Application.Info.Version.ToString)
    End Sub
    Private Sub RefreshFiles()
        'loop around each path and loads the files.
        For Each filePath As String In IO.Directory.GetFiles(SourceFolder, "*.*", SearchOption.AllDirectories).Where(Function(x)
                                                                                                                         Return (New String() {".vlm", ".VLM"}).
                                                                                       Contains(System.IO.Path.GetExtension(x))
                                                                                                                     End Function)
            _dtFiles.Rows.Add(New Object() {filePath, IO.Path.GetFileName(IO.Path.GetFileName(filePath))})
        Next
    End Sub

    Private Sub txtPartNum_TextChanged(sender As Object, e As EventArgs) Handles txtPartNum.TextChanged
        If String.IsNullOrWhiteSpace(txtPartNum.Text) Then
            _bsFiles.RemoveFilter()
        Else
            _bsFiles.Filter = String.Format("FileName LIKE '%{0}%'", txtPartNum.Text)
        End If
    End Sub
    Private Sub txtPartNum_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPartNum.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If
    End Sub
    Private Sub lstPartNum_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstPartNum.KeyDown
        Dim theFile = lstPartNum.SelectedValue
        If e.KeyCode = Keys.Enter Then
        End If
        If theFile IsNot Nothing And rbnEditPat.Checked Then
            System.Diagnostics.Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE", theFile)
        End If
        If theFile IsNot Nothing And rbnBurnPat.Checked Then
            System.Diagnostics.Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE", theFile)
        End If
    End Sub
    Private Sub lstPartNum_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lstPartNum.MouseDoubleClick
        Dim theFile = lstPartNum.SelectedValue
        If theFile IsNot Nothing And rbnEditPat.Checked Then
            System.Diagnostics.Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE", theFile)
        End If
        If theFile IsNot Nothing And rbnBurnPat.Checked Then
            System.Diagnostics.Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE", theFile)
        End If
    End Sub
End Class

Open in new window


OK so I did some investigating and found another way to skin the cat. Problem is the new code comes up with the same errors. I changed the list box mouse double click sub to the following code:

 Private Sub lstPartNum_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lstPartNum.MouseDoubleClick
        Dim theFile = lstPartNum.SelectedValue
        If theFile IsNot Nothing And rbnEditPat.Checked Then
            Dim procedit As New Process
            procedit.StartInfo.FileName = "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE"
            procedit.StartInfo.Arguments = SourceFolder + theFile
            procedit.Start()
        End If
        If theFile IsNot Nothing And rbnBurnPat.Checked Then
            Dim procburn As New Process
            procburn.StartInfo.FileName = "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"
            procburn.StartInfo.Arguments = SourceFolder + theFile
            procburn.Start()
        End If
    End Sub

Open in new window

burn-error-1.jpg
burn-error-2.jpg
edit-error-1.jpg
edit-error-2.jpg
edit-error-3.jpg
form-ss.JPG
Visual Basic.NET.NET ProgrammingMicrosoft DevelopmentVisual Basic ClassicWindows OS

Avatar of undefined
Last Comment
Steve Williams

8/22/2022 - Mon