473,385 Members | 1,732 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,385 software developers and data experts.

FindWindow in a Service DLL

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
5 7032
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: lauren quantrell | last post by:
I have an Access application with the name: MyAppName® It has the "®" symbol (ChrW$(&H00AE)) at the end of it. If I remane the application without the "®" symbol, I can use FindWindow to close the...
5
by: Tony | last post by:
I need to send a message to a window in another application. The name of the window is known at design time and set in the constant App2_MONITOR_CAPTION. The message is defined as X_GenerateEvent....
3
by: kd | last post by:
Hi All, I need to check whether an application is executing. I do not know the class name of the application; however, I know the window caption of the application. What would be the first...
3
by: Bob | last post by:
Hi, Trying to determine if a program is running or not. I implemented the example code below but I am getting handles returned regardless of whether a program exists or not. i.e. You can feed in a...
0
by: victor | last post by:
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...
0
by: ntm | last post by:
Hi all you good m8 I try to make my first small program in vb, but im not very succesfull :D (Im using Visual Studio 2005) Form my own program i will like to set focus on an other running...
0
by: Jim S | last post by:
Is looping FindWindow() ok? We have a simple little c# 2.0 app that’s sole purpose is to look for a dialog box from another app to pop up and then click it’s OK button. To do this we use a...
2
by: Alex | last post by:
Dear coleagues, I am trying to call FindWindow function but it seems not to be working. It returns a loooooong value even if the Window "SoftMaxPro GxP" is not started. I can't even find a...
1
by: musai | last post by:
Hi Members how to use findwindow API for outlook application let us example For excel we use to find excel FindWindow("XLMAIN", vbNullString)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...

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.