Q:

Waiting till process end

Hello i have to write program which have to open a few system properties like:
Process sound = new Process();
sound.StartInfo.FileName = "mmsys.cpl";
sound.Start();

// Place 1

Process device = new Process();
device.StartInfo.FileName = "hdwwiz.cpl";
device.Start();

// Place 2

// Other Code doing sth

And that works well, but my problem is that i must on first run mmsys.cpl, wait for user check what he must to do, and after closing window run hdwwiz.cpl.
So in // Place 1 i wrote: 
sound.WaitForExit();

But that dont works, because mmsys.cpl is only shortcut and run as process "explorer.exe", and hdwwiz.cpl runs as "mmc.exe", so that comand doesnt wait till closing that windows, and run both at once.
Is any way to make sth like i want ?

A:

What you are running are called control panel files.  Legacy ones, like mmsys.cpl are hosted in a processed with the name rundll32.exe  You could get poll the list of these processes using:
Process[] processes = Process.GetProcessessByName("rundll32.exe");

and call WaitForExit on these Process objects.  You can do the same for newer mmc.exe based .CPL's.
Obviously, this is not a great solution if there are multiple control panel applets running at the same time.  You could perhaps put up a warning to the user close the other ones in this case.
Other more complicated solutions might involve using pinvoke to call the Win32 function EnumWindows to get a list of top level windows and hook them to watch for the WM_CLOSE message.

