Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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);
Posted
Updated 5-May-17 2:23am
v2
Comments
Richard MacCutchan 5-May-17 7:25am    
You have a call to process.Kill(); which is most likely the problem.
Member 11095926 5-May-17 8:16am    
Thanks Richard, i have updated my code, it still have issue... it perfectly open first instance of chrome and place inside panel, it open second instance as well but do not place inside another panel.
F-ES Sitecore 5-May-17 8:21am    
If you want the second instance in a different panel then you need to give that panel's handle. Your code is hard-coded to always use panel2
Member 11095926 5-May-17 8:44am    
I did same, but it says process exited, so requested information is not available..
Member 11095926 5-May-17 14:44pm    
if process is killed the chrome window will also disposed, this is not required answer

1 solution

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 article: [GetProcesses]
 
Share this answer
 
v2
Comments
Member 11095926 5-May-17 8:48am    
ofcourse.. you are right but i need to open both processes inside my application, i already wrote a piece of code to check if any process with same name exist, if its already running then kill them and then open two new process for my app.
Wessel Beulink 5-May-17 8:59am    
Didn't see that part in solution. Looks like a weird behavior of the chrome application. Is there a reason to not use a browser or extension for winforms ?
Member 11095926 5-May-17 9:29am    
send me an email at sibghat.bsse@gmail.com so i can send you complete project for better understanding...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900