Link to home
Start Free TrialLog in
Avatar of RyanH11
RyanH11Flag for Australia

asked on

Trouble closing Google Chrome browser from within VB.net

I have an automation program that I'm developing that is doing most of what I want it to do.  I can open various web browsers without a problem.

When it comes to closing them, Firefox, Opera and Safari all close fine using the code

 
Dim p As Process() = Process.GetProcessesByName(SelectedBrowserName)
            For i = 0 To p.Count - 1
                        p(i).CloseMainWindow()
                        Do Until p(i).HasExited = True
                            Thread.Sleep(100)
                        Loop
                    Next

Open in new window


Google Chrome however doesn't respond at all.  The only way I can get it to close is to use the 'kill' command which causes some grief when I next load up Chrome.  

I'm not 100% certain, but I'm pretty sure it used to work fine and has only started doing this in recent updates.  Can anybody offer a suggestion that reliably works with the current version of Chrome?

Cheers
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Each process is associated with a tab it's possible the processes don't have a MainWindowHandle so for each process instance it means the MainWindowHandle could be zero. You might be able to filter by checking if MainWindowHandle of the process is greater then zero then use .CloseMainWindow
Avatar of RyanH11

ASKER

It has worked properly in all testing to date.  Many thanks.