473,795 Members | 3,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem connecting an event handler to IE in a Windows service

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
"shellWindo ws = new SHDocVw.ShellWi ndowsClass();":

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.ServiceP rocess.ServiceB ase
{
private System.Componen tModel.Containe r components = null;
private static SHDocVw.ShellWi ndows shellWindows = null; //<=====

public Service1()
{
InitializeCompo nent();
}

static void Main()
{
System.ServiceP rocess.ServiceB ase[] ServicesToRun;
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new
Service1() };
System.ServiceP rocess.ServiceB ase.Run(Service sToRun);

if(!EventLog.So urceExists("Ser vice1"))
{
EventLog.Create EventSource("Se rvice1", "Applicatio n");
}
}

private void InitializeCompo nent()
{
this.ServiceNam e = "Service1";
}

protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose(di sposing);
}

protected override void OnStart(string[] args)
{
EventLog.WriteE ntry("Service1" , "0.This is just a test.",
EventLogEntryTy pe.Information) ;

shellWindows = new SHDocVw.ShellWi ndowsClass(); //<=====
foreach(SHDocVw .InternetExplor er ie in shellWindows) //<=====
ie.BeforeNaviga te2 += new
SHDocVw.DWebBro wserEvents2_Bef oreNavigate2Eve ntHandler(this. ie_BeforeNaviga t
e2); //<=====
}

public void ie_BeforeNaviga te2(object disp, ref object url, ref
object flags, ref object targetFrameName , ref object postData, ref object
headers, ref bool cancel) //<=====
{
EventLog.WriteE ntry("Service1" , "ie_BeforeNavig ate2.",
EventLogEntryTy pe.Information) ; //<=====
}

protected override void OnStop()
{
}
}
}
Nov 22 '05 #1
2 2653
Hello,

Thanks for your post. As I understand, the problem you are facing is that
it fails to enumerate existing IE windows from a Windows Service. Please
correct me if there is any misunderstandin g. I now share the following
information with you:

Based on my experience, I believe the reason of the problem is that a
Windows Service is running in a hidden window station and desktop other
than "WinSta0\Defaul t". To work around this problem, you may have to set
your service as an interactive service b the following steps:

1. Go to "Control Panel" -> "Service".
2. Select the service in list box and click "Startup" button.
3. Select "System Account" and check "Allow Service to Interact with
Desktop".

I belive the following article is helpful:
Interacting with the User in a Service
http://msdn.microsoft.com/library/de...us/dllproc/bas
e/interacting_wit h_the_user_in_a _service.asp

I look forward to your result.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 22 '05 #2
Hello,

Thanks for your post. As I understand, the problem you are facing is that
it fails to enumerate existing IE windows from a Windows Service. Please
correct me if there is any misunderstandin g. I now share the following
information with you:

Based on my experience, I believe the reason of the problem is that a
Windows Service is running in a hidden window station and desktop other
than "WinSta0\Defaul t". To work around this problem, you may have to set
your service as an interactive service b the following steps:

1. Go to "Control Panel" -> "Service".
2. Select the service in list box and click "Startup" button.
3. Select "System Account" and check "Allow Service to Interact with
Desktop".

I belive the following article is helpful:
Interacting with the User in a Service
http://msdn.microsoft.com/library/de...us/dllproc/bas
e/interacting_wit h_the_user_in_a _service.asp

I look forward to your result.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
463
by: SunshineGirl | last post by:
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.
10
3499
by: SunshineGirl | last post by:
In my code, class A instanciates classes B and C. I would like class B to connect an event handler to a method in class A, and for class C to disconnect that event handler. I think I've done too much thinking, and now I'm even more confused as to how to accomplish this as when I started. Any help will be appreciated.
3
5135
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library. When i try to connect to a server that doesnt exist it raises a "Connection forcibly rejected by the resmote host" SocketException.
2
2531
by: Stampede | last post by:
Hi guys 'n' girls, I want to use callback methods when using BeginInvoke on some events. So far no problem, but know I thought about what could happen (if I'm not completly wrong). Lets say an event is triggerd with BeginInvoke and a callback funktion which is part of the instanze which is also holding the event. So the call looks something like this: public class MyClass {
5
1589
by: John | last post by:
Hi I am trying to get web reference to my first (!) web service which is on a remote host. I am getting the following error; Server Error in '/' Application. Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application
11
1842
by: Kevin Antel | last post by:
We have written a service that uses a timer control to check for a process every 60 seconds. This is installed on a Windows 2003 Server w/SP1. The problem we are running into is that the service doesn't stop, but it seems the timer process stops. Has anyone else run into this? What have been solutions?
18
3350
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I run the code on my local computer but I do have it when I run the code on geocities.
0
3925
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP connection protocol on server for particular instance. Becuase I think
1
5580
by: chitra g | last post by:
Hi, I tried all the options below but did not work. Your suggestions please.
1
7128
by: Simon | last post by:
Hi all, I'm having a problem creating a global exception handler in a windows service that I'm making. Another poster suggested that the way to do this was to use the CurrentDomain.UnhandledException event to catch and deal with any exception that crops up. The problem is, when I try and deliberately throw an exception in my services OnStart event handler, nothing seems to happen. By that I mean, the CurrentDomain_UnhandledException...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.