From: khuedinhpham on
I run into a problem and hope that someone may help me out. Here is
the summary of what I am doing:

1. I create a NT service
2. The service is a multi-threaded application that listen on some
port (winsock)
3. Whenever a connection is make the service will spin-off a thread to
deal with the connection (through some communication protocol that I
devise)

This works perfectly and I don't have any problem with it.

Now, I try to do a little extra, when a connection is coming, I want to
set the light on the keyboard (e.g. NumLock/Caps/Scroll) to flash to
notify the user that there is a connection.

I first follow some example in MSDN, with both keybd_event and
SendInput API's, and create a stand-alone program (console program)
and the standalone program works fine -> Light on keyboard is flashing.

Now I try to incorporate the code come the stand-alone program into the
service and nothing happens. I did debug by insert a message to be
displayed before and after the code calling and both display perfectly.
Somehow the program just ignore the keypress simulating in between
those 2 message displays.

I further code a KeyLogger program as another standalone program. This
works perfectly as designed (e.g. all key pressed are recorded into a
file, etc.) I then try to incorporate the code from KeyLogger program
into the service and again nothing show up (all compile/run/test are
working fine. Somehow the service just ignore the part of the code
that log the key press. Very much look like the problem above).

Since the code is working fine as a stand-alone program then I thought
I should the executable from within the Service by using CreateProcess
or ShellExecute API's. Again, nothing work-> e.g. the program just
ignores the call to the executable (otherwise, it works fine without
any problem)

Previously I did experience this problem: When I create the service
and then call MessageBox API's then it doesn't work (eg. no message is
display) so I re-read the manual page for MessageBox and figure out
that I must use the option MB_SERVICE_NOTIFICATION to display a message
when it runs as a service. It is legitimate to use that option since
Service is intended to run WITHOUT user interaction so if you want to
display a message then you got to get that option within the API's
call.

Now I just wonder if is there anything similar to that when I call a
keypress simulation ? Since keypress is interpreted by Service as an
user interaction. Then there may be something must be called before
calling other API's, etc. I don't know what it is and hope that
someone did this before can give me a helping hand.

Regards,

Khue

From: Craig Kelly on
<khuedinhpham(a)yahoo.com> wrote:

> Now I just wonder if is there anything similar to that when I call a
> keypress simulation ? Since keypress is interpreted by Service as an
> user interaction. Then there may be something must be called before
> calling other API's, etc. I don't know what it is and hope that
> someone did this before can give me a helping hand.

I believe your service must be configured to "Interact With Desktop".

Craig


From: Arnaud Debaene on
Craig Kelly wrote:
> <khuedinhpham(a)yahoo.com> wrote:
>
>> Now I just wonder if is there anything similar to that when I call a
>> keypress simulation ? Since keypress is interpreted by Service as an
>> user interaction. Then there may be something must be called before
>> calling other API's, etc. I don't know what it is and hope that
>> someone did this before can give me a helping hand.
>
> I believe your service must be configured to "Interact With Desktop".

.... and it shouldn't, since it is a serious security hole that won't be
available on Vista (google for "shatter attack" if you want the details).

For Khue : As you have said it yourself, a service is not intended to have
any user interface, and you shouldn't try to put it one.
Suppose your service is running on a Terminal Server box, with 10 users
logged in : what would you do? Log the 10 keyboards simultanously? Same
question about the LED thingy...

If your service need to interact with the user one way or another, you
should write a GUI app that is started when a user log in (put it in the
startup folder, or in the registry ...). That app should communicate with
the service through some kind of IPC (socket, COM, Event, Memory Mapped
File, whatever you like).

Arnaud
MVP - VC


From: khuedinhpham on
Thanks so much for the responses. Especially to Craig. That is
exactly what I want and my application works perfectly now. I was
struggling for few days about this problem but could not find out why
it skipped the code.

Thank you to Arnaud for your thinking. However, my service is intended
to run on individual PC (not server) and I want some user interaction
when I need it.

Regards,


Khue

From: Lawrence Groves on

"Arnaud Debaene" <adebaene(a)club-internet.fr> wrote in message
news:OSkwpAM4FHA.2352(a)TK2MSFTNGP12.phx.gbl...
>
> Craig Kelly wrote:
>> <khuedinhpham(a)yahoo.com> wrote:
>>
>>> Now I just wonder if is there anything similar to that when I call a
>>> keypress simulation ? Since keypress is interpreted by Service as an
>>> user interaction. Then there may be something must be called before
>>> calling other API's, etc. I don't know what it is and hope that
>>> someone did this before can give me a helping hand.
>>
>> I believe your service must be configured to "Interact With Desktop".
>
> ... and it shouldn't, since it is a serious security hole that won't be
> available on Vista (google for "shatter attack" if you want the details).

I remember reading somewhere that this default can be turned off in Vista.
Am I worng?

I never understood the reasoning behind services not interacting with the
desktop before I read about shatter attacks. BUT, there are cases when
interaction is something that is useful, but still safe.... such as in
closed systems, or those on a closed network. I don't facny changing a whole
mass of legacy code just because Microsoft decides to cut out this
functionallity!!!

Loz.