Well, I spent a little time on this site figuring out how to start the “child” process (i.e. the new parent window set for me) using Win32 calls from C #. It works like this until it crosses the boundaries of the UAC. Good.
Now I'm trying to do this with the uninstall program (process A), which loads a temporary program (process B) that actually does the job. Process A leaves after creating B. My code requires a process identifier from which to get a window handle that is passed to SetParent. It looks something like this:
Process p = new Process();
try
{
p.EnableRaisingEvents = true;
p.StartInfo.FileName = fileName;
p.StartInfo.Arguments = arguments;
if (p.Start())
{
p.WaitForInputIdle(10000);
IntPtr pHwnd = p.MainWindowHandle;
if (pHwnd == IntPtr.Zero)
{
return null;
}
IntPtr currentHwnd = Process.GetCurrentProcess().MainWindowHandle;
if (SetParent(pHwnd, currentHwnd) == 0)
{
if (Marshal.GetLastWin32Error() == 5)
{
}
else
{
return null;
}
}
Works great until p leaves. In this case, p starts the arrow after starting p '. Despite this, p never has a window handle.
, p, , p ' (, , ) p'? HWND id, .
!