473,402 Members | 2,053 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,402 software developers and data experts.

Getting the hWnd of an IE window from an NT service

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.

Jan 18 '06 #1
5 4098
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
<Mr*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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.

Jan 18 '06 #2
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.

Jan 19 '06 #3
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
<Mr*******@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.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.

Jan 19 '06 #4
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.

Jan 26 '06 #5
<Mr*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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/is...04/ManagedSpy/

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

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

Similar topics

5
by: hellrazor | last post by:
Hi there, First of all, I'm very much a C++ amateur (i.e., a newb). I'm having to program a win32 system service for my employer, and I'm almost done with the task, but I need help with...
4
by: wallacej | last post by:
I am trying to retrieve a selected value from a listbox and store it in a string (char) variable. I am using the following code: calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOPTS,(WPARAM)0,...
5
by: Tedmond | last post by:
Dear all, How can I get all the titles of all openning windows? I found a API in win32 that called EnumWindows() but it returns only the windows handles, not titles. How can I get the list just...
8
by: Salad | last post by:
I designed a small app and I wanted to do a BrowseFolder (see http://www.mvps.org/access/api/api0002.htm), basically do a file open diaglog and select a directory/folder. The problem is that you...
1
by: | last post by:
I'm trying to get (or set) the focus on an external window but to no avail. I've imported the "GetActiveWindow" and "GetFocus" from the user32.dll but those 2 functions seem to only work for windows...
6
by: kurotsuke | last post by:
Hi, I need to know the position (X, Y cohordinates) of the caret. I'm using the function: private static extern int GetCaretPos(ref POINT lpPoint); I'm actually getting a result but I...
2
by: shalender verma | last post by:
Hello All I am using VB 6. I am trying to get the text in the tittle bar of the window i click by using GetWindowText API function but its not working. Here is the code i am using:- Private...
2
by: siddharthkhare | last post by:
Hi All, I am launching a IE using following code. ======================================================================= m_IeProcess = new Process(); m_IeProcess.StartInfo.WindowStyle =...
11
by: =?ISO-8859-15?Q?Kolja_M=E4rtens?= | last post by:
Hello! I've been professionally working on java projects for several years, but have done extremely little C/C++ coding and just a few little things in VB.Net. Right now I'm trying to write a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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...

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.