473,781 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnost ics.Process.Get ProcessById to get information about the
processes.

What I had planned to do was get the hWnd from the process with
process.MainWin dowHandle, 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("S hell.Applicatio n")
If Not objShell Is Nothing Then
For Each objIE In objShell.Window s
If Microsoft.Visua lBasic.Left(obj IE.LocationURL, 4)
= "http" Then
URLString &= objIE.LocationU RL & " "
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 4114
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*******@gmai l.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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.Diagnost ics.Process.Get ProcessById to get information about the
processes.

What I had planned to do was get the hWnd from the process with
process.MainWin dowHandle, 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("S hell.Applicatio n")
If Not objShell Is Nothing Then
For Each objIE In objShell.Window s
If Microsoft.Visua lBasic.Left(obj IE.LocationURL, 4)
= "http" Then
URLString &= objIE.LocationU RL & " "
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*******@gmai l.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.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*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.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
1495
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 something that appears to be very basic. I have a function within the cpp file called StopService: void StopService() {
4
5640
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, LPARAM)0); SendMessage(hWnd,(UINT)LB_GETTEXT,(WPARAM)calibIndex,(LPARAM)selectedCalib); Where IDC_LIST_CALIBOPTS is the list and selectedCalib is the variable where I want the value to go.
5
4697
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 like the Applications tab in Windows Task Manager? Thanks, Tedmond
8
3986
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 can't specify the starting folder. Stephan Leban provided a neat solution that does allow me to browse using a starting folder. I am using A97 and it works fine. However, I put it onto a system that uses AccessXP. And it chokes on...
1
2278
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 my application owns... I can get the hWnd of the process I want to check/set focus on. Any help would be greatly appresated. Just to be a little more clear, say NotePad is up; I'm trying to make my program set focus to the opened Notepad...
6
8030
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 think that refers to the cohordinates of the Textbox the caret is in and not the screen
2
1951
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 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpszString As String, ByVal cch As Long) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
2
1916
by: siddharthkhare | last post by:
Hi All, I am launching a IE using following code. ======================================================================= m_IeProcess = new Process(); m_IeProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; m_IeProcess = Process.Start("IExplore.exe","www.ABC.com"); ======================================================================= how do i get refrence to the InternetExplorer from the process.
11
4639
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 Windows Service in VC++ .Net thats supposed to use a 3rd party SDK do receive Image data and send it out through a webservice.
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
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
7485
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
6727
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
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.