2

I'm fairly new to c# and this forum in general but as far as I'm concerned, I haven't seen any question like mine that will solve my problem.

I'm calling the method Process.WaitForExit() to wait until an installation file finishes to install. However, the method seems to consider the UAC as the 'process' and activates after I click OK on the UAC. Is there a better way to wait for an installation process to finish before the code proceeds? Or am I doing it wrong? Disabling the UAC manually (if that's possible) is a no go unless it's done programmatically as well.

Here's the part of the code:

Edit: proper calling of process

Process netInstall = Process.Start(filePath + "\\Installer.exe");
netInstall.WaitForExit();
Console.WriteLine("Installation Finished!");

Edit 2: Would it help if I say I'm installing MySQL Server 5.6? It seems that, besides the Security Warning, it pops up and close some windows before it starts too. Regards.

user2595220
  • 53
  • 1
  • 1
  • 4
  • What are you trying to do? Are you saying you are capturing the UAC instead of your launched executable in the `netInstall` process? – Shark Jul 18 '13 at 11:23
  • I need to wait until the `netInstall` (which is an installer exe) to finish installing before proceeding to the `WriteLine` part of the code. But somehow, after I click OK on the UAC of the installer and the UAC window closes, it proceeds to the `WriteLine`. Thanks for the quick reply by the way. :) – user2595220 Jul 18 '13 at 11:29
  • you do realize that you aren't starting the installer in the `netInstall`'s instance space, but rather statically? – Shark Jul 18 '13 at 11:30
  • Oh, sorry about that. I've changed it like BayStallion's answer below but it still doesn't cover my main concern. The `WaitForExit()` still activates after I've closed some initial windows from the installer (UAC, Security Warning). I need it to finish the installation proper before proceeding. :) – user2595220 Jul 18 '13 at 11:43

2 Answers2

0

The code is not correct. You create an instance of the Process class, but then you call the static method Process.Start, which creates a new instance of Process.

Your code should look like this:

Process netInstall = Process.Start(filePath + "\\Installer.exe");
netInstall.WaitForExit();
Console.WriteLine("Installation Finished!");
  • 1
    Thanks for the info, but it still doesn't address my main concern about the `WaitForExit()` activating before the installer proper finishes. I'll update the main thread with that code. :) – user2595220 Jul 18 '13 at 11:46
0

Run your your application with elevated privileges:

<requestedExecutionLevel level="requireAdministrator">

Also consider BasyStallion answer and correctly start netInstall

Sam Aleksov
  • 1,201
  • 6
  • 12
  • I have already elevated the privilege. I still have the Security Warning popping up and when I close it, it still activates the `WaitForExit()`. – user2595220 Jul 18 '13 at 11:45