Search code examples
vb.netopenfiledialog

OpenFileDialog under the hood


This is my first question here because I ended up in dead end. I'm using ZIP 2 Secure EXE (very good software from Chilkat) to create setup.exe for application. ZIP 2 Secure EXE can be run without GUI with one or more parameters.
The problem is that when I call ZIP 2 Secure EXE (ChilkatZipSE.exe) without using OpenFileDialog form to determine location of ChilkatZipSE.exe, it doesn't run process with System.Diagnostics.Process class. The way I call ChilkatZipSE.exe is "..\ChilkatZipSE.exe -cfg settings.xml". Everything is OK with settings.xml and there is UnlockCode node which is needed for creating setup.exe file. When I use OpenFileDialog ChilkatZipSE.exe creates desired setup.exe and it's working fine.
Bellow is my code that I use:

Private Sub btnStartApp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartApp.Click

    If txtExtAppPath.Text.Length > 0 AndAlso System.IO.File.Exists(txtExtAppPath.Text) Then

        Dim myFile As New FileInfo(txtExtAppPath.Text)
        txtExtAppLog.Text = StartApplication(myFile.FullName, txtExtParams.Text, chkIsHidden.Checked)
        'txtExtAppLog.Text = StartApplication(txtExtAppPath.Text, txtExtParams.Text, chkIsHidden.Checked)

    End If

End Sub

Public Function StartApplication(ByVal fileFullPath_ As String, ByVal fileParameter_ As String, ByVal isHidden_ As Boolean) As String

    Dim lassie As String = String.Empty

    Try

        Dim newProcess As New ProcessStartInfo()
        newProcess.FileName = fileFullPath_
        newProcess.Arguments = fileParameter_
        If isHidden_ Then newProcess.WindowStyle = ProcessWindowStyle.Hidden

        If System.IO.File.Exists(fileFullPath_) Then

            Using startedNewProcess As Process = Process.Start(newProcess)
                'startedNewProcess.EnableRaisingEvents = True
                startedNewProcess.WaitForExit()
            End Using

        Else

            lassie = "File " + fileFullPath_ + " doesn't exist."

        End If

    Catch ex As Exception

        lassie = ex.Message

    End Try

    Return lassie

End Function

Thanks, magnumx.


Solution

  • the problem was the given parameter. When using OpenFileDialog it knows where settings.xml is. But when calling "..\ChilkatZipSE.exe -cfg settings.xml" without OpenFileDialog it must be used as "..\ChilkatZipSE.exe -cfg ..\settings.xml"