3

I am creating a wpf application that needs a prerequisite. If that prerequisites is not met then I ask the user if he will like to install the prerequisite that happens to be: Microsoft Visual C++ 2010 SP1 Redistributable Package.

So if the user chose to install the prerequisite I will execute vcredist_x86.exe (that is the file that get's downloaded from the first link that I provided).

Then on my application I will be able to tell when the installation is complete by doing something like:

ProcessStartInfo psi = new ProcessStartInfo(@"vcredist_x86.exe");
var p = new Process(); p.StartInfo = psi; 

p.Start(); //start the process
p.WaitForExit(); // wait for the installation to finish

// installation should be done now

Ok everything works great so far. The problem is that I have a progress bar in my wpf application and I will like to show the progress in there.

I have been able to show the progress of the installation by doing the following:

There is a program called AutoIt that it is great for automating simple tasks. For example I can easily detect if a window exists with autoit by using something like:enter image description here

I could then compile that script and create a very small executable. In that executable I will return 1 if the specified window exists or 0 otherwise.

When the user moves to the next window my script might return 2 because that is a different window. AutoIt can also see the progress of a progress bar of a window!!! so if that script returns 80 for example then I will update my progress to 80% for instance.

I do that by doing something like:

// start the autoitExecutable....

// wait for executable to exit usually takes 10 miliseconds it is fast

if (autoitProcess.ExitCode == 1)
{
   // do somthing
}else if(autoitProcess.ExitCode == 2)
{
   // do something else
 } //etc....

As you can see I have to execute that script every 1 second to detect what changes have been done in order to update my progress bar in WPF. That works but every time I execute that executable with c# I get the:

enter image description here

cursor for about 500 milliseconds then on the next second it appears again. That becomes annoying even though no windows show up. It will be nice if I could get rid of that cursor and execute that executable silently somehow. when I execute the autoit executable there are no windows that show up nor nothing else.

P.S.

I know I could use c# to check for the existance of a window and maybe see the value of other window's handler's just like autoit is able to do it but it is so simple to create those programs with AutoIt and it will be nice if I could use AutoIt instead of C# for this kind of taks

H.B.
  • 166,899
  • 29
  • 327
  • 400
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
  • That seems like a **lot** of hard work for something that comes for free with an installer project (prereq checking+installation). – spender Feb 14 '12 at 22:14
  • on your p.WaitForExit() i know that there is a way to do that in a While loop have you tried that..? – MethodMan Feb 14 '12 at 22:16
  • Kick the install off in another thread show an animation while it's going. Pseudo progress bars, gah.. – Tony Hopkinson Feb 14 '12 at 22:20
  • The circle wait cursor appears every time I execute an executable. the way I am able to communicate with the executable is by seeing it's return code (therefore the exe has to terminate) that's why I want to execute it several times. I also know I can include this in the prerequisites of my application but I will like to know how to do it just to learn. I could also remove the progress bar and make it even easier. I get a lot of great answers in here maybe I learn something new... – Tono Nam Feb 14 '12 at 22:26
  • In other words if I execute the exe just once I will just get the wait circle cursor for 500 miliseconds and that's it. The problem comes when executing that process several times. If I execute it every second I will get the circle cursor every second and then that is when it becomes a problem – Tono Nam Feb 14 '12 at 22:30

2 Answers2

1

I saw this behavior when the exe was set to "windows application" rather than "console application".

Changing the type to console no longer gives a busy cursor at launch.

jperkins
  • 19
  • 1
0

You could add an event handler as well for example

System.Diagnostics.ProcessStartInfo p = new 
     System.Diagnostics.ProcessStartInfo(@"vcredist_x86.exe") ;
p.Arguments="-RunForever";
proc = new System.Diagnostics.Process();
proc.StartInfo = p;
proc.EnableRaisingEvents = true;
proc.Exited += new EventHandler(myProcess_Exited);
proc.Start();

inside the event if I wanted to do something like this

// Inside the form class:

private System.Diagnostics.Process proc;

private void myProcess_Exited(object sender, System.EventArgs e)
{
    button3.BackColor=Color.LightGreen;  //success indicator
}

if you wanted to do this in a While Loop you could also do something like this for example but you would have to change the params to fit your case example code you can utilize

while(!autoitProcess.WaitForExit(someTimeout))
{ 
   if(ShouldCancel)
   {
      break;
   }
}

does this make sense or help out...?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
  • in your first block of code you have: proc.Start(); the process takes 500 milliseconds to execute. I am constantly running that proc.Start(); . Every time I use the proc.Start(); I get the circle cursor for 400 milliseconds which is not a bath thing. But since I am running the proc.Start(); every second then I get the circle thing every second. Hope I am explaining my self – Tono Nam Feb 14 '12 at 22:34