如何在C#windows窗体应用程序中打开多个chrome浏览器实例 [英] How to open multiple instances of chrome browsers in C# windows form application

查看:866
本文介绍了如何在C#windows窗体应用程序中打开多个chrome浏览器实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这项技术的新手,如果我犯了任何错误,请不要理睬。我正在开发一个应用程序,用户可以在不同的Chrome实例上登录其他帐户。我已经在隐身模式下编写了一段代码并打开了多个chrome窗口,但当我将它们放在我的C#应用​​程序中时,它说Process已经退出,所以请求的信息不可用...

我的代码是



我的尝试:



i am new in this technique so kindly ignore if i make any mistake. I am developing an application where users can sign in to different account on different instances of Chrome. I already wrote a piece of Code and its opening multiple windows of chrome in incognito mode but when i place them inside my C# application, it says Process has exited, so the requested information is not available...
My code is

What I have tried:

try
            {
                Process process = new Process();
                process.StartInfo.FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
                process.StartInfo.Arguments = "http://www.google.com/" + " --new-window --incognito ";
                process.Start(); 
                if (!process.HasExited)
                {
                    Thread.Sleep(5000);
                    SetParent(process.MainWindowHandle, panel2.Handle);
                    MoveWindow(process.MainWindowHandle, -3, -70, panel2.Width + 3, panel2.Height + 70, false);
                }
 }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }


    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("USER32.dll")]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

推荐答案

开始创建具有进程ID的线程后。



您需要先获取currentProcess才能获得该过程的信息。



After you start its creating a thread with a process id.

You need to get you currentProcess first before you can get information of the process.

if (!process.HasExited) { 
 Process currentProcess = Process.GetCurrentProcess();
}





msdn文章: [ GetProcesses ]


这篇关于如何在C#windows窗体应用程序中打开多个chrome浏览器实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆