C# using launch arguments after the tool restart

83 Views Asked by At

How could I use launch arguments, after the application restartet?

I'm passing the arguments the following way:

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);
}

Now the tool would upgrade and restart, but how could I use the passed arguments stored in launchArgs on the new restart?

2

There are 2 best solutions below

4
On

The arguments passed can be accessed in the entry method.

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

It looks like you are already doing that. If you are wanting those persisted somehow, I would consider putting them in a variable in your instance, and when you get the update command, pull them from there and pass them along