473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
"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(ServicesToRu n);

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_BeforeNavigate2EventHan dler(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()
{
}
}
}
Nov 22 '05 #1
2 2618
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 misunderstanding. 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\Default". 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_with_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 misunderstanding. 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\Default". 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_with_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
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...
10
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...
3
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....
2
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...
5
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...
11
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...
18
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...
0
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...
1
by: chitra g | last post by:
Hi, I tried all the options below but did not work. Your suggestions please.
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.