S
SunshineGirl
I'm trying to connect an event handler to the BeforeNavigate2 event of
Internet Explorer. This works in a Windows app, but I can't get it to work
in a Windows service. I get the following exception when I run the line
"shellWindows = new SHDocVw.ShellWindowsClass();":
COM object with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} is either not
valid or not registered.
I know that this CLSID belongs to the ShellWindows interface.
Any ideas?
Here's the source code:
namespace WindowsService1
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.ComponentModel.Container components = null;
private static SHDocVw.ShellWindows shellWindows = null; //<=====
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
if(!EventLog.SourceExists("Service1"))
{
EventLog.CreateEventSource("Service1", "Application");
}
}
private void InitializeComponent()
{
this.ServiceName = "Service1";
}
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Service1", "0.This is just a test.",
EventLogEntryType.Information);
shellWindows = new SHDocVw.ShellWindowsClass(); //<=====
foreach(SHDocVw.InternetExplorer ie in shellWindows) //<=====
ie.BeforeNavigate2 += new
SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.ie_BeforeNavigat
e2); //<=====
}
public void ie_BeforeNavigate2(object disp, ref object url, ref
object flags, ref object targetFrameName, ref object postData, ref object
headers, ref bool cancel) //<=====
{
EventLog.WriteEntry("Service1", "ie_BeforeNavigate2.",
EventLogEntryType.Information); //<=====
}
protected override void OnStop()
{
}
}
}
Internet Explorer. This works in a Windows app, but I can't get it to work
in a Windows service. I get the following exception when I run the line
"shellWindows = new SHDocVw.ShellWindowsClass();":
COM object with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} is either not
valid or not registered.
I know that this CLSID belongs to the ShellWindows interface.
Any ideas?
Here's the source code:
namespace WindowsService1
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.ComponentModel.Container components = null;
private static SHDocVw.ShellWindows shellWindows = null; //<=====
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
if(!EventLog.SourceExists("Service1"))
{
EventLog.CreateEventSource("Service1", "Application");
}
}
private void InitializeComponent()
{
this.ServiceName = "Service1";
}
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Service1", "0.This is just a test.",
EventLogEntryType.Information);
shellWindows = new SHDocVw.ShellWindowsClass(); //<=====
foreach(SHDocVw.InternetExplorer ie in shellWindows) //<=====
ie.BeforeNavigate2 += new
SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.ie_BeforeNavigat
e2); //<=====
}
public void ie_BeforeNavigate2(object disp, ref object url, ref
object flags, ref object targetFrameName, ref object postData, ref object
headers, ref bool cancel) //<=====
{
EventLog.WriteEntry("Service1", "ie_BeforeNavigate2.",
EventLogEntryType.Information); //<=====
}
protected override void OnStop()
{
}
}
}