By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

FindWindow in a Service DLL

P: n/a
Help ....

This is my situation:
I've made two apps, a Managed C# and an Unmanaged MFC. The C# app
communicates with the MFC-app via (Win32-API) PostMessage, done with
the P/Invoke method. One of the activities is "FindWindow". Everything
works fine.
Until ...: I needed the same procedure within another context: now I
need to communicate the C# with a web service (dll) running somewhere
on a Server machine. This doesnot work anymore!
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!
Thank you.

;-( victor
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
A service really shouldn't interact with the desktop. I believe the SYSTEM
account can, but that's only meant for debugging purposes, as I understand.

If you really want to go down this dangerous road, there's a hack for
getting around it here:
http://www.codeproject.com/csharp/Cs...iceDesktop.asp

I would really recommend you find a better communication mechanism, like
sockets.

Pete
<victor> wrote in message news:h1********************************@4ax.com...
Help ....

This is my situation:
I've made two apps, a Managed C# and an Unmanaged MFC. The C# app
communicates with the MFC-app via (Win32-API) PostMessage, done with
the P/Invoke method. One of the activities is "FindWindow". Everything
works fine.
Until ...: I needed the same procedure within another context: now I
need to communicate the C# with a web service (dll) running somewhere
on a Server machine. This doesnot work anymore!
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!
Thank you.

;-( victor

Nov 17 '05 #2

P: n/a
Pete, thank you for your response!
As you/ve probably guessed, I'm quite a novice on this 'service'
matters. Hence, I'm totally reliant on people like you. So, following
your link-tip (CodeProject) I've learned a lot more by now!
I did the coding section of Robert Davis - alas, still with no result;
meaning: FindWindow still reponds with a null and, what worries me
more: I can't find the key entry of my service in the Registry!
This brings me to the tought of: is Davis' code executed in my
service-DLL? I've put it right after the 'InitializeComponent();'
line. Is this the right place?

greetz, victor
------------------------------------------------------------------------------------------
On Thu, 3 Nov 2005 10:23:59 -0600, "Pete Davis"
<pdavis68@[nospam]hotmail.com> wrote:
A service really shouldn't interact with the desktop. I believe the SYSTEM
account can, but that's only meant for debugging purposes, as I understand.

If you really want to go down this dangerous road, there's a hack for
getting around it here:
http://www.codeproject.com/csharp/Cs...iceDesktop.asp

I would really recommend you find a better communication mechanism, like
sockets.

Pete
<victor> wrote in message news:h1********************************@4ax.com...
Help ....

This is my situation:
I've made two apps, a Managed C# and an Unmanaged MFC. The C# app
communicates with the MFC-app via (Win32-API) PostMessage, done with
the P/Invoke method. One of the activities is "FindWindow". Everything
works fine.
Until ...: I needed the same procedure within another context: now I
need to communicate the C# with a web service (dll) running somewhere
on a Server machine. This doesnot work anymore!
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!
Thank you.

;-( victor


Nov 17 '05 #3

P: n/a
Victor,

This needs to be done in the service installer, not in the service itself.

What's happening is he's modifying the registry and setting a bit in the
flag that allows the service to interact with the desktop. The Service
Manager then uses this information when it starts the service. So it must be
set before the service actually runs.

Pete

<victor> wrote in message news:qi********************************@4ax.com...
Pete, thank you for your response!
As you/ve probably guessed, I'm quite a novice on this 'service'
matters. Hence, I'm totally reliant on people like you. So, following
your link-tip (CodeProject) I've learned a lot more by now!
I did the coding section of Robert Davis - alas, still with no result;
meaning: FindWindow still reponds with a null and, what worries me
more: I can't find the key entry of my service in the Registry!
This brings me to the tought of: is Davis' code executed in my
service-DLL? I've put it right after the 'InitializeComponent();'
line. Is this the right place?

greetz, victor
------------------------------------------------------------------------------------------
On Thu, 3 Nov 2005 10:23:59 -0600, "Pete Davis"
<pdavis68@[nospam]hotmail.com> wrote:
A service really shouldn't interact with the desktop. I believe the SYSTEM
account can, but that's only meant for debugging purposes, as I
understand.

If you really want to go down this dangerous road, there's a hack for
getting around it here:
http://www.codeproject.com/csharp/Cs...iceDesktop.asp

I would really recommend you find a better communication mechanism, like
sockets.

Pete
<victor> wrote in message
news:h1********************************@4ax.com. ..
Help ....

This is my situation:
I've made two apps, a Managed C# and an Unmanaged MFC. The C# app
communicates with the MFC-app via (Win32-API) PostMessage, done with
the P/Invoke method. One of the activities is "FindWindow". Everything
works fine.
Until ...: I needed the same procedure within another context: now I
need to communicate the C# with a web service (dll) running somewhere
on a Server machine. This doesnot work anymore!
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!
Thank you.

;-( victor

Nov 17 '05 #4

P: n/a
No it's not, please follow the samples given in MSDN on how to implement a
Service using the framework.
But I'm affraid this will never work, because your service has no top level
window (and should not have on) and even if it has one (say you created and
instance of a Form and run a message loop), you won't be able to use it to
get messages from processes running on other machines using Postmessage.
Also I'm not clear why you want to use Postmessage to pass messages to a Web
service??
Willy.

<victor> wrote in message news:qi********************************@4ax.com...
Pete, thank you for your response!
As you/ve probably guessed, I'm quite a novice on this 'service'
matters. Hence, I'm totally reliant on people like you. So, following
your link-tip (CodeProject) I've learned a lot more by now!
I did the coding section of Robert Davis - alas, still with no result;
meaning: FindWindow still reponds with a null and, what worries me
more: I can't find the key entry of my service in the Registry!
This brings me to the tought of: is Davis' code executed in my
service-DLL? I've put it right after the 'InitializeComponent();'
line. Is this the right place?

greetz, victor
------------------------------------------------------------------------------------------
On Thu, 3 Nov 2005 10:23:59 -0600, "Pete Davis"
<pdavis68@[nospam]hotmail.com> wrote:
A service really shouldn't interact with the desktop. I believe the SYSTEM
account can, but that's only meant for debugging purposes, as I
understand.

If you really want to go down this dangerous road, there's a hack for
getting around it here:
http://www.codeproject.com/csharp/Cs...iceDesktop.asp

I would really recommend you find a better communication mechanism, like
sockets.

Pete
<victor> wrote in message
news:h1********************************@4ax.com. ..
Help ....

This is my situation:
I've made two apps, a Managed C# and an Unmanaged MFC. The C# app
communicates with the MFC-app via (Win32-API) PostMessage, done with
the P/Invoke method. One of the activities is "FindWindow". Everything
works fine.
Until ...: I needed the same procedure within another context: now I
need to communicate the C# with a web service (dll) running somewhere
on a Server machine. This doesnot work anymore!
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!
Thank you.

;-( victor

Nov 17 '05 #5

P: n/a
victor wrote:
My assumption is that the service-dll is *not* running in a
UserInteractive mode, and therefore cannot perform the "FindWindow"
function. (It keeps returning a zero handle ....)
Or, am I doing something wrong?
Somebody have an idea how to solve this?
Help is very much appreciated!


Well, it does run on a desktop, but as you say, not the interactive
desktop. If the service has the appropriate (NT) security privileges it
can get access to all the WindowStations on the machine (a WindowStation
is an NT secure object). From the WindowStation you can get access to
the Desktop objects running there, and hence enumerate the windows.
You'll have to do all of that with platform invoke.

http://msdn.microsoft.com/library/en...d_desktops.asp

See EnumWindowStations, EnumDesktops and EnumDesktopWindows.

BTW the interactive WindowStation is called Winsta0.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.