I am trying to run cmd command in windows application in C#. My code is,
progressBar1.Show();
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
progressBar1.Step = 1;
ProcessStartInfo ProcessInfo;
Process Process;
for (int i = 0; i < 300000; i++)
{
progressBar1.PerformStep();
int percent = (int)(((double)progressBar1.Value/(double)progressBar1.Maximum) * 100);
progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial",(float)7.02,FontStyle.Regular),Brushes.Black, new Point(progressBar1.Width / 2 - 10, progressBar1.Height / 2 -7));
ProcessInfo = new ProcessStartInfo(command);
ProcessInfo.RedirectStandardOutput = true;
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
Process = Process.Start(ProcessInfo);
Process.Close();
}
progressBar1.Hide();
Problem is, if I run the command in command promt; it installs the driver in couple of second but if I run the command in C# it doesn’t work.
Can anyone explain me, is there any code I am missing or not?
command is
ExecuteCommand("\"C:\\Disk1.Win7\\setup.exe\" /s /f1\"C:\\Disk1.Win7\\setup_install.iss\" /a\"C:\\Disk1.Win7\\OposData.reg\"");
Consider moving the code for running your COMAMND,
Outside of that “for” loop. Adding a WHILE loop which runs the driver installer, with the for loop embedded within it.
This may solve your problem. You’re on the right track, just consider aligning things a little differently. As Alvin and a few others stated, your COMMAND is only being processed for 3ms, before it is shut down, and started again; to a maximum of 300000 times. Things just need to be moved around.