Services and Application.Run

  • Thread starter Thread starter Simon Tamman
  • Start date Start date
S

Simon Tamman

Will Application.Run() work within a service? (e.g. will the message pump be
operational)
My service works as an exe but not a service, i'm wondering it's it's due to
that.

Kind Regards

Simon
 
Simon,

You are sure that your service has not any user interface at all?

Cor
 
There is no UI, it's trying to pick up ALL the keydown events from the
WinAPI via: SetWindowsHookEx in user32.dll.
The application's aim is to just disable the keyboard.
For the API call to work it needs an Application.Run() somewhere to get the
windows message pump running.
In my console app I spawn a thread to hook up the events and then call
Application.Run() that works fine. However, now i've converted it into a
service it no longer works.

Wah.

Any ideas?
 
Simon Tamman said:
There is no UI, it's trying to pick up ALL the keydown events from the
WinAPI via: SetWindowsHookEx in user32.dll.
The application's aim is to just disable the keyboard.
For the API call to work it needs an Application.Run() somewhere to get the
windows message pump running.
In my console app I spawn a thread to hook up the events and then call
Application.Run() that works fine. However, now i've converted it into a
service it no longer works.

Wah.

Any ideas?
 
Simon Tamman said:
There is no UI, it's trying to pick up ALL the keydown events from the
WinAPI via: SetWindowsHookEx in user32.dll.
The application's aim is to just disable the keyboard.
For the API call to work it needs an Application.Run() somewhere to get the
windows message pump running.
In my console app I spawn a thread to hook up the events and then call
Application.Run() that works fine. However, now i've converted it into a
service it no longer works.

Wah.

Any ideas?

You are trying to read/process "windows messages", so you effectively have a User Interface.
This is not possible because the service runs in the context of a non-interactive
desktop/winsta,. For a service to run in the same context as an interactive user, you'll
have to set the "interact with desktop" which requires the service to run in the
"localsystem" account. Note that you should only enable this for debugging purposes, and
it's something which won't work on Vista anyway.

Willy.
 
Thank you very much for your help!
Sure enough setting that checkbox to true allows it to run and receive the
events correctly.

Why should this method of operation be only advisable for debugging, is
there a problem with using it in production?

Kind Regards

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top