Hack Forums
[C#] Hide chrome selenium browser by window handle - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Hide chrome selenium browser by window handle (/showthread.php?tid=5760339)



Hide chrome selenium browser by window handle - Kyogo - Nov 29, 2017

I was able to hide the process(selenium chrome browser) by using FindWindow and the lpWindowname by changing the browser title with Javascript. But I want to be able to hide the process(selenium chrome browser) by a different handle since the window name changes everytime it navigates to a different page.

Here is my code:
Code
[DllImport("user32.dll")]
   static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

   [DllImport("user32.dll")]
   static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

   const int SW_HIDE = 0;
   const int SW_SHOW = 5;

   private void button1_Click_1(object sender, EventArgs e)
   {
       if (on)
       {

           IntPtr hWnd = FindWindow(null, "Window Name - Google Chrome");
           if (hWnd != IntPtr.Zero)
           {

               ShowWindow(hWnd, SW_HIDE); // Hide the window
           }

           button1.Text = "Show";
           t.Start();
           on = false;

       }
       else {

           IntPtr hWnd = FindWindow(null, "Window Name - Google Chrome");
           if (hWnd != IntPtr.Zero)
           {
               ShowWindow(hWnd, SW_SHOW); //Show Window

           }

           button1.Text = "Hide";
           t.Stop();
           on = true;
       }



RE: Hide chrome selenium browser by window handle - Kyogo - Dec 4, 2017

bump still need help with this


RE: Hide chrome selenium browser by window handle - totenkopf - Dec 4, 2017

Code
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

Look into OpenProcess()
https://msdn.microsoft.com/en-ca/library/windows/desktop/ms684320(v=vs.85).aspx

It returns the handle, you should be able to read/write even when you've changed the process name.

You can also look into WriteProcessMemory() for changing the process name opposed to using JavaScript, and approach it using the typical read/write process methods. 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681674(v=vs.85).aspx