Search code examples
c#.netregistrysystem.diagnosticsprocessstartinfo

How do you run a program you don't know where the arguments start?


The subject doesn't say much cause it is not easy to question in one line. I have to execute a few programs which I read from the registry. I have to read from a field where somebody saves the whole paths and arguments.
I've been using System.Diagnostics.ProcessStartInfo setting the name of the program and its arguments but I've found a wide variety of arguments which I have to parse to save the process executable file in one field and its arguments in the other.

Is there a way to just execute the whole string as is?


Solution

  • I have tackled this the same way as the poster above, using cmd.exe with process start info.

    Process myProcess = New Process;
    myProcess.StartInfo.FileName = "cmd.exe";
    myProcess.StartInfo.Arguments = "/C " + cmd;
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    myProcess.StartInfo.CreateNoWindow = True;
    myProcess.Start();
    myProcess.WaitForExit();
    myProcess.Close();
    

    cmd /c carries out the command, and then terminates. WaitForExit will terminate the process if it runs for too long.