![]() IntPtr handle = process.MainWindowHandle Public static void BringProcessToFront(Process process) Process process = Process.GetProcessesByName("iexplore") ![]() ![]() Static extern bool SetForegroundWindow(IntPtr hWnd) If you want to grad some web sites, I recommend that you could use IExplore to do it. I suggest that you don't use Chromium or Chrome browser because I find that SetForegroundWindow method is inapplicable for them based on my test. My PC is running Windows 10 (Version 1903) and I am use Visual Studio 2019 (Version 16.1.6).īased on your description, you want to bring an application to front in c#. I want to get the Chromium window, but my code is not working.īy the way, as it is already 2019, are there any way to do the same job without using Windows API? But Chrome is not the window I want to bring to front. I can always get the result if I open Google Chrome browser in my PC. Process process = Process.GetProcessesByName( "Chrome" ) Process process = Process.GetProcessesByName( "Chromium" ) To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.Įven I can see from Task Manager that there are always at least 2 Chromium processes are running, but my program can’t detect any of them. ![]() Process process = Process.GetProcessesByName("Chromium") Ĭonsole.Write("Proccess found: " process.ToString()) Ĭonsole.WriteLine("ERROR: Application is not running!\nException: " ex.Message) Įxception: Index was outside the bounds of the array.Ĭ:\Program Files\dotnet\dotnet.exe (process 16720) exited with code -1. Public static extern bool SetForegroundWindow(IntPtr hWnd) I searched around, and I got some code, like the following: (.Net Core Console Project with C# 7.3) Therefore, I guess if I can write another program, can always bring the Puppeteer Sharp window to the front, then I don’t have to do this by hand. Like the URL detect and click are affected, therefore, they don’t work from time to time, but if I keep the Puppeteer Sharp window (showing the Chromium page) in front, then usually, the Puppeteer Sharp program works. As the web browsers hide Puppeteer Sharp window, then some actions, But from time to time, when I browse internet, web browsers are in front. I have a C# Console Project using Puppeteer Sharp to grab some web pages.
0 Comments
Leave a Reply. |