Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET Launching Batch File not working after install
    primarykey
    data
    text
    <p>Okay, this is one that has me stumped beyond belief. I have a program that is to be installed on different machines that is supposed to execute a batch file after it has completed a specific task. The batch file is configured via our webservice by the user, and the application pulls this path string down and then executes the file at that path. Should be pretty simple/straightforward, right?</p> <p>The code:</p> <pre><code>Private Function ExecuteBatchFile(batchFilePath As String) As String Try Dim psi As New ProcessStartInfo(batchFilePath) psi.RedirectStandardError = True psi.RedirectStandardOutput = True psi.CreateNoWindow = False psi.UseShellExecute = False Dim process As Process = process.Start(psi) process.WaitForExit() ExecuteBatchFile = process.ExitCode Catch ex As Exception StrAppStatus = "Error within execution of batch file: " &amp; ex.Message LogMe(StrAppStatus) Return "Fail" End Try End Function </code></pre> <p>Now, for the tricky part. This code works perfectly when running in the dev environment. I have yet to have an issue. HOWEVER, when the application is installed on any computer (including the same one the IDE is installed on), when it gets to the step in it's overall process that calls this function, it does not actually launch the batch file. Keep in mind, it never throws an exception, on either side. It also does not return an exitcode to that string, as i have other logging to track that as well.</p> <p>There are only two possibilities I can think of in this case. Either A:) there is a permissions issue where the application is not allowed to launch batch files on the computer it is installed on, or B:) this sub is called by a thread that was spun off from the main thread (i.e. using the <code>MyThread = New System.Threading.Thread(AddressOf TheMainLoop) MyThread.Start()</code> command). </p> <p>Still the fact that it works 100% of the time during the compile and run phase in the IDE but not after an install is blowing my mind.</p> <p><strong>EDIT 1:</strong> Just did a test where I placed a button on the main form itself, and the click event does the same thing as the earlier function, and it works, even after an install. This leads me to believe that it will only work if it is launched using the main thread... What do you all think?</p> <p><strong>EDIT 2:</strong> The batch file is a very simple test batch that opens a text file, and I know that the batch file and path are both fine, because when compiled it works fine. Also, edit 1 was stating that I created a simple button that executes the same code from above, and it works fine after an install. Since that was done on the main thread, and the code from earlier was done in a separate thread spun off from the original, I was wondering if that was the cause of the issue. The other crazy thing is that my logging catches if the file launches or not, and it almost acts as if it is launching when I have that original issue. Bah, this whole thing is just nuts.</p> <p><strong>EDIT 3:</strong> Added the answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload