Link to home
Start Free TrialLog in
Avatar of kvishnusharma
kvishnusharmaFlag for Afghanistan

asked on

How to close IE tabs/browser windows through C# ASP.NET web application

I have a web application which should check for Internet Explore (IE) windows that are open using the name of the web page and close them. Below is the code that I am using to accomplish that.
This piece of code runs well and closes the IE windows when I run it from my local machine/host. But when I install the web application on the development server, it fails and throw an exception. Does the COM component "Shell.Application" supposed to be used only on windows application. What should I do to close browser windows/tabs on a client side from a web site?

private void IEBrowserTabClose()
        {
            string filename;            
            try
            {
                ShellWindows shellWindows;
                Type typeShell = Type.GetTypeFromProgID("Shell.Application");
                object objectShell = Activator.CreateInstance(typeShell);

                if (typeShell != null)
                {
                    shellWindows = typeShell.InvokeMember("Windows", BindingFlags.InvokeMethod, null, objectShell, null) as ShellWindows;

                    foreach (SHDocVw.InternetExplorer ie in shellWindows)
                    {
                        filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                        if (filename.Equals("iexplore"))
                        {
                            if (ie.LocationName == "Google")
                            {
                                ie.Quit();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _PageErrorMsg = Common.GetDisplayableText(ex.Message);
            }

        }
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

<html>
<body onload="window.open('', '_self', '');">

<input type="button" class="inputfields" onclick="javascript:window.opener='x';window.close();" value="Close" />
</body>
</html>

Avatar of kvishnusharma

ASKER

Looks like you cannot control client processes from a website...it's far fetched...Shellwindows are more appropriate for the windows application I believe.. Thanks for the reply..
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
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