kvishnusharma
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("Sh ell.Applic ation");
object objectShell = Activator.CreateInstance(t ypeShell);
if (typeShell != null)
{
shellWindows = typeShell.InvokeMember("Wi ndows", BindingFlags.InvokeMethod, null, objectShell, null) as ShellWindows;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExt ension(ie. FullName). ToLower();
if (filename.Equals("iexplore "))
{
if (ie.LocationName == "Google")
{
ie.Quit();
}
}
}
}
}
catch (Exception ex)
{
_PageErrorMsg = Common.GetDisplayableText( ex.Message );
}
}
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("Sh
object objectShell = Activator.CreateInstance(t
if (typeShell != null)
{
shellWindows = typeShell.InvokeMember("Wi
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExt
if (filename.Equals("iexplore
{
if (ie.LocationName == "Google")
{
ie.Quit();
}
}
}
}
}
catch (Exception ex)
{
_PageErrorMsg = Common.GetDisplayableText(
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<body onload="window.open('', '_self', '');">
<input type="button" class="inputfields" onclick="javascript:window
</body>
</html>