In Windows 11, The following code is able to run and get the main window handle of winver.exe
:
public IntPtr Start()
{
IntPtr id = 0;
using (Process process = Process.Start("c:\\Windows\\System32\\winver.exe"))
{
for (int i = 0; i < 10 && id == 0; i++)
{
Thread.Sleep(200);
try
{
process.WaitForInputIdle();
} catch { }
process.Refresh();
id = process.MainWindowHandle;
}
return id;
}
return 0;
}
However changing 'winver.exe' for 'calc.exe', 'notepad.exe' or any store download application will result on a window handle of 0, which I assume is related to those being UWP apps (but I'm far from being an expert in anything Windows related).
Is there any way to run and fetch the main window handle of a UWP app from C#?