2014-02-09 69 views
1

我是新來的visual studio和新的stackoverflow。這個網站一直很有幫助。 我做了一個按鈕來運行一個.exe和它的世界。我現在試圖運行帶有參數的.exe文件,但不知道如何。我正常運行它與一個.bat文件,但想切換到.exe。visual studio運行.exe參數

這裏是與我通常運行的參數.bat。

program.exe -o www.website.com -u user -p password 

這裏是Visual Studio按鈕,我已經

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 

如何運行這些參數的.exe文件。感謝您的時間和幫助。

回答

4

Process.Start有一個重載需要兩個參數,第二個是你想傳遞給你的進程的參數列表。

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 

你也可以看看,需要一個ProcessStartInfo,使以微調您啓動所需的過程中對環境的過載

接收應用程序可以訪問的參數使用類似代碼傳遞這一個

For Each pp in My.Application.CommandLineArgs 
    MessageBox.Show(pp) 
Next 
+0

對不起,跳上一個問題,但你能寫出如何在新啓動的.exe文件中讀取這些參數嗎?提前致謝。 – Hoh

+0

參數傳遞給目標程序,你可以用'My.Application.CommandLineArgs'檢索它們,或者你可以修改你的Main函數直接從那裏讀取它們。嘗試搜索'在VB.NET中讀取命令行參數',你會發現很多有用的鏈接 – Steve

+0

所以,基本上你是傳遞參數作爲數組,然後解析它們,對吧? – Hoh