Home All Groups Group Topic Archive Search About

Getting the hWnd of an IE window from an NT service

Author
18 Jan 2006 5:54 AM
MrBewsher
Hi,

I'm using VB.Net and writing an NT service that runs in the system
account in the background with no interaction with the desktop.

I'm running it on XP Pro.

I'd like to get the URL of any Internet Explorer process a logged in
user is running.
I can get a list of process IDs and from that use
System.Diagnostics.Process.GetProcessById to get information about the
processes.

What I had planned to do was get the hWnd from the process with
process.MainWindowHandle, but this seems to always return 0.  I'm
guessing that this is something to do with the service running in the
background.

So then I tried a different approach with the following code:

            objShell = CreateObject("Shell.Application")
            If Not objShell Is Nothing Then
                For Each objIE In objShell.Windows
                    If Microsoft.VisualBasic.Left(objIE.LocationURL, 4)
= "http" Then
                        URLString &= objIE.LocationURL & " "
                    End If
                Next
            End If

This works from a standard desktop app and gets a list of the URLs in
all open IEs, but when I run it as part of the service, the first line
fails with "Class Not Registered".  Again I'm guessing that this is
because I'm running in the background.

So now I'm at a dead end.  I can get the processID of the iexplore
process, but can't get the windows handle and therefore I can't get any
further...  but...  well it's there somewhere!  There has to be a way
to get it!

I would really appreciate any light that could be shed on this problem.

Mr B.

Author
18 Jan 2006 5:28 PM
Jevon
Have you got your service set to be able to interact with the desktop? It's
an option somewhere but my experience of services is limited so you'll need
to Google if you can't find it :)

Jevon


<MrBews***@gmail.com> wrote in message
Show quoteHide quote
news:1137563650.300261.114330@g47g2000cwa.googlegroups.com...
> Hi,
>
> I'm using VB.Net and writing an NT service that runs in the system
> account in the background with no interaction with the desktop.
>
> I'm running it on XP Pro.
>
> I'd like to get the URL of any Internet Explorer process a logged in
> user is running.
> I can get a list of process IDs and from that use
> System.Diagnostics.Process.GetProcessById to get information about the
> processes.
>
> What I had planned to do was get the hWnd from the process with
> process.MainWindowHandle, but this seems to always return 0.  I'm
> guessing that this is something to do with the service running in the
> background.
>
> So then I tried a different approach with the following code:
>
>            objShell = CreateObject("Shell.Application")
>            If Not objShell Is Nothing Then
>                For Each objIE In objShell.Windows
>                    If Microsoft.VisualBasic.Left(objIE.LocationURL, 4)
> = "http" Then
>                        URLString &= objIE.LocationURL & " "
>                    End If
>                Next
>            End If
>
> This works from a standard desktop app and gets a list of the URLs in
> all open IEs, but when I run it as part of the service, the first line
> fails with "Class Not Registered".  Again I'm guessing that this is
> because I'm running in the background.
>
> So now I'm at a dead end.  I can get the processID of the iexplore
> process, but can't get the windows handle and therefore I can't get any
> further...  but...  well it's there somewhere!  There has to be a way
> to get it!
>
> I would really appreciate any light that could be shed on this problem.
>
> Mr B.
>
Author
19 Jan 2006 6:01 AM
MrBewsher
I've set it not to interact with the desktop.  I'm wanting it to run in
the background.

Hmmm...  here's a question then... What are the disadvantages of making
it interact with the desktop?

Mr B.
Author
19 Jan 2006 10:20 AM
Jevon
But surely you want it to interact with the desktop to be able to grab the
window handles? It can still run in the background, my impression was just
that allowing the interaction meant the service could "see" the logged in
users' desktops. However, as I said in my original reply, this might be
incorrect. Unfortunately I can't advise you on this as I haven't really
worked with services.

Jevon


<MrBews***@gmail.com> wrote in message
Show quoteHide quote
news:1137650496.229816.69060@g49g2000cwa.googlegroups.com...
> I've set it not to interact with the desktop.  I'm wanting it to run in
> the background.
>
> Hmmm...  here's a question then... What are the disadvantages of making
> it interact with the desktop?
>
> Mr B.
>
Author
26 Jan 2006 12:43 PM
MrBewsher
Thanks Jevon

Sorry for the long time not replying to this.  I'll have a look into it
and try to see if it works with interact with desktop enabled.  Been a
bit busy lately and this is a "spare time" project.

What you are saying makes sense.  I think I'm going to have to google
to find out what the difference is, but if it is as you say, then I
can't understand the need for a setting that disables interaction with
the desktop...  If the only thing that the setting does is stop a
service from doing something (rather than enabling it to do something
else), then what's the point in including the setting?  Unless it's a
security thing...  ho hum... I think it's time to google :-)

Thanks for your help.  If I ever figure out my problem (or find out
what the point of the interact setting is), then I'll write back and
let you know.

Mr B.
Author
3 Mar 2006 9:12 PM
Ken Halter
<MrBews***@gmail.com> wrote in message
news:1138279400.188959.324730@g43g2000cwa.googlegroups.com...
> Thanks Jevon
>
> Thanks for your help.  If I ever figure out my problem (or find out
> what the point of the interact setting is), then I'll write back and
> let you know.
>
> Mr B.

I'm not sure if it's already been mentioned... or would even help but...
since I had the browser window open, looking at the article, I thought I'd
post this......

Deliver The Power Of Spy++ To Windows Forms With Our New Tool
http://msdn.microsoft.com/msdnmag/issues/06/04/ManagedSpy/

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..