By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,419 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,419 IT Pros & Developers. It's quick & easy.

Open new IE after closed ERROR!

P: n/a
Hi All, I am trying to open a new instance of IE at the start of my C# application.

When user press Start Recording... My applicaiton will close that specific instance of IE and Open a fresh IE, but if that instance is closed manually, then the App must still be able to open a new fresh IE...

It give me the following erro message:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ieObjTest.exe

Here is my Code.

using SHDocVw;
using System.Diagnostics;

InternetExplorer browser;
protected Process[] processes;
protected Process browserProcess;

public frmSiteAlert()
{
InitializeComponent();

// detect if IE is already running ?
processes = Process.GetProcessesByName("IEXPLORE");

if(processes.Length >= 1)
MessageBox.Show(processes.Length + " Running Copies of internet Explorer has been Detected... ");

// Get the Screen resolution
this.Size = new Size(getScreenWidth(), getScreenHeight()* 30/100);
this.MinimumSize = new Size(200, getScreenHeight()* 30/100);
// Display the form in the top let corner of the screen.
this.StartPosition = FormStartPosition.Manual;
openBrowser();
}

static void Main()
{
Application.Run(new frmSiteAlert());
}

public void openBrowser()
{
browser = new InternetExplorer();
browserProcess = Process.GetCurrentProcess();
if (browser != null)
{
browser.Height = getScreenHeight() *70/100-30;
browser.Width = this.Width;
browser.Top = getScreenHeight()*30/100;
//opened = true;
browser.Visible = true;
object obj = null;
browser.Navigate("about:blank", ref obj, ref obj, ref obj, ref obj);
}

}
// When Start Recording is pressedd
private void miStartRecording_Click(object sender, System.EventArgs e)
{
if(browserProcess.HasExited)
{
openBrowser();
}
else
{
browser.Quit();

/// HERE THE BROGRAM BREAKS !!!!!!!!!!!!!!!

openBrowser();
}
}
private int getScreenWidth()
{
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
return screenWidth;

}
private int getScreenHeight()
{
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
return screenHeight;
}
--------------------------------
Thanks
From: awsok fakry

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>sxzBcSmpoEOc2uL23w9QMg==</Id>
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.