2016-12-21 51 views
1

如何在應用程序重新啓動後使用啓動參數?C#在工具重啓後使用啓動參數

我傳遞參數的方式如下:

private void updateApplication(string tempFilePath, string currentPath, string newPath, string launchArgs) 
{ 
    string argument = "/C Choice /C Y /N /D Y /T 4 & Del /F /Q \"{0}\" & Choice /C Y /N /D Y /T 2 & Move /Y \"{1}\" \"{2}\" & Start \"\" /D \"{3}\" \"{4}\" {5}"; 
    ProcessStartInfo info = new ProcessStartInfo(); 

    info.Arguments = string.Format(argument, currentPath, tempFilePath, newPath, Path.GetDirectoryName(newPath), Path.GetFileName(newPath), launchArgs); 
    info.WindowStyle = ProcessWindowStyle.Hidden; 
    info.CreateNoWindow = true; 
    info.FileName = "cmd.exe"; 
    Process.Start(info); 
} 

現在工具將升級並重新啓動,但我怎麼能使用存儲在launchArgs在新的重啓傳遞的參數?

+0

將參數傳遞給新的啓動 – Steve

回答

0

傳入的參數可以在輸入方法中訪問。

class Program 
{ 
    static void Main(string[] args) 
    { 
      // args contains the arguments passed at startup. 
    } 
} 
+0

也是我我一直在嘗試,現在我很遺憾地收到以下錯誤: 沒有給出的參數對應於'startUp.startUp(string [])'所需的形式參數'args' – dnxc

+0

因爲它不會得到一個參數只有在更新後才能在正常啓動時傳遞。 – dnxc

+0

你想重新啓動命令提示嗎? – Agalo

0

看起來你已經這麼做了。如果你想要以某種方式持續存在,我會考慮將它們放在你的實例中的一個變量中,並且當你得到更新命令時,將它們從那裏拉出並傳遞給它們。