Hi @Thanga Perumal Ramasamy (SX/ETM12-EM) ,
You can use the ShowWindowAsync function and the SetForegroundWindow function to activate and bring your app window to the foreground.
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main(string[] args)
{
string processName = "YourApplicationName";
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 0)
{
IntPtr mainWindowHandle = processes[0].MainWindowHandle;
ShowWindowAsync(mainWindowHandle, 3);
SetForegroundWindow(mainWindowHandle);
}
else
{
Console.WriteLine("Application not found.");
}
}
}
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.