How can I minimize the IE Browser using C#? I tried the code mentioned below which didn’t work:
var processes = Process.GetProcessesByName("*iexplorer.*");
if (processes.Any())
{
var handle = processes.First().MainWindowHandle;
ShowWindow(handle, SW_SHOWMINIMIZED);
}
Are there any other methods to achieve minimizing of the IE Browser?
As Damien says, there is no fullproof way to do this as the user owns the browser, not your app. Your code isn’t working because you are trying to use a wildcard symbol (*) like you would do on Google, but this doesn’t work here.
GetProcessesByNameis literally looking for a process named*iexplorer.*. You can confirm this by placing a breakpoint underneath this line, and hovering overprocessList, it is an empty array. Changing this toiexplorefixes this problem.Some tested and working code is below: