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>