Reputation: 21
I am new to visual studio and new to stackoverflow. This site has been very helpful in great was. I have made a button to run a .exe and it world well. I am now trying to run that .exe with arguments and dont know how. I normal run it with a .bat file but would like to switch it over to .exe.
Here is the .bat with the arguments i normally run.
program.exe -o www.website.com -u user -p password
Here is the visual studio button i have made
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("E:\test\program.exe")
End Sub
End Class
How do I run the .exe with those arguments. Thank you for you time and help.
Upvotes: 2
Views: 7601
Reputation: 216243
Process.Start has an overload that takes two parameters, the second one is the arguments list that you want to pass to your process.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("E:\test\program.exe", "-o www.website.com -u user -p password")
End Sub
End Class
You could also look at the overload that takes a ProcessStartInfo that allow to fine tune the environment in which you start the required process
The receiving application can get access to the parameters passed using code similar to this one
For Each pp in My.Application.CommandLineArgs
MessageBox.Show(pp)
Next
Upvotes: 7