Reputation: 19
Hello been searching for a while but all I get are results that is talking about moon travel and e=mc2.
So in order to be as specific as possible I'll include screenshots :)
Story:
I've added an .exe file within my project like so; Screenshot of Solution Explorer What I want to do is to press a button and it will launch the application:
Private Sub RunVersion11ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunVersion11ToolStripMenuItem.Click
Dim TeamViewer11Path As String = ("C:\Program Files (x86)\TeamViewer\TeamViewer.exe")
Process.Start(TeamViewer11Path)
End Sub
Private Sub RunVersion12packedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunVersion12packedToolStripMenuItem.Click
Dim TeamViewer12Path As String = ("?!?!?!?! this file is included in the proj as seen in picture 1, the Private Sub above this is a locally installed one.")
Process.Start(TeamViewer12Path)
End Sub
As you can see above the first sub executes an application that is already installed on the machine. The 2nd sub I want to run the .exe as shown in the above picture.
However after googling etc, everything is refering to the full path of the file like: C:\Users\XXXX\documents\visual studio 2017\Projects\WindowsApp6\WindowsApp6\ts12.exe
But obviously this wont work if I run the application on another computer.
What I want help with:
What should I put in my Process.Start to point to a file included in the solution explorer? like Process.Start("\root\app\ts3.exe") or similar, that works both in debug and release.
Please note that I'm a newbie, so please provide examples that makes sense for someone way below your own level of expertise. Thanks! :)
Upvotes: 1
Views: 1169
Reputation: 9193
You'll want to ensure that the Copy to Output Directory property on the .exe file in your solution explorer is set to Copy If Newer or Alway Copy.
Code to get to the output directory:
Dim strOutputDirectory As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Process.Start(System.IO.Path.Combine(strOutputDirectory, "ts12.exe"))
Upvotes: 1