Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to receive Window-Messages (WM_...) in my serviceapplication?

579 views
Skip to first unread message

AStringlist

unread,
Feb 1, 2008, 4:29:02 AM2/1/08
to
Is there any possibility do receive WindowMessages (wm_UserChanged-Messages)
in my serviceapplication?

With "allocateHWnd" i installed a WndProc in the service. And with the
api-function "WTSRegisterSessionNotification" i already get
"WM_WTSSESSION_CHANGE"-messages inside this WndProc. But unfortunately no
other WindowMessages, it seems. Is it necessary to register the WndProc in
any way first (eventually with "registerClass" or something)?

Any ideas somewhere?

Thx in advance.

Greetings,
AStringlist

Paul

unread,
Feb 1, 2008, 9:17:57 AM2/1/08
to
You will need a message loop for that.
A service application already has en message loop, but if you use a
secondary thread, than this thread must have a message loop also.

In the private section of the service, add:
FWinHandle : HWND;
procedure WndProc(var msg: TMessage);

in serviceCreate add
FWinHandle:= Classes.AllocateHWND(WndProc);

in procedure TMySvc.WndProc(var msg: TMessage);
begin
if Msg.Msg = WM_... then ...

end;


Paul


"AStringlist" <1737...@gmx.net> schreef in bericht
news:47a2...@newsgroups.borland.com...

AStringlist

unread,
Feb 1, 2008, 11:36:02 AM2/1/08
to
Thx, but how i wrote in my first post i already did it in this way
(installed a WndProc using allocateHWnd..).


The reason why i'm looking for this is to make the service able to record
the Logon/Logoffs off all users on my PC. For XP that works using
"WTSRegisterSessionNotification". But unfortunately Windows 2000 Prof.
doesn't know this api-function!

...and so it became necessary to find another way to detect this
Logon/Logoffs under W2k. Perhaps via detecting wm_UserChanged ...with a
WndProc which can this WMessage catch?

...becaus the normal WndProc (installed with allocateHWnd) cannot see this
WM_UserChanged-Message.

?


PS. or does anybody knows another way to detect Logon/Logoffs under Windows
2000 Prof.?


Peter Below (TeamB)

unread,
Feb 1, 2008, 1:26:20 PM2/1/08
to
AStringlist wrote:

> Is there any possibility do receive WindowMessages
> (wm_UserChanged-Messages) in my serviceapplication?
>
> With "allocateHWnd" i installed a WndProc in the service. And with
> the api-function "WTSRegisterSessionNotification" i already get
> "WM_WTSSESSION_CHANGE"-messages inside this WndProc. But
> unfortunately no other WindowMessages, it seems. Is it necessary to
> register the WndProc in any way first (eventually with
> "registerClass" or something)?

Services usually do not run in the users desktop and windows messages
cannot pass between desktops. You can register a handler function with
SetConsoleCtrlHandler, this handler then gets notified on user logoff
and system shutdown, but there is no notification for user logon.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Remy Lebeau (TeamB)

unread,
Feb 1, 2008, 3:38:42 PM2/1/08
to

"AStringlist" <1737...@gmx.net> wrote in message
news:47a2...@newsgroups.borland.com...

> Is there any possibility do receive WindowMessages
> (wm_UserChanged-Messages) in my serviceapplication?

No, because services do not have their own HWNDs to begin with. Even if
they did, a window message is not allowed to pass over desktop/workstation
boundaries.

> With "allocateHWnd" i installed a WndProc in the service. And
> with the api-function "WTSRegisterSessionNotification" i already
> get "WM_WTSSESSION_CHANGE"-messages inside this
> WndProc.

If you read the documentation for WTSRegisterSessionNotification() again, it
has the following note:

"To receive session change notifications from a service, use the
HeaderEx() function"

That is the best way to handle this, as a service's HandlerEx() callback
will receive SERVICE_CONTROL_SESSIONCHANGE events. If you are using
TService, however, then you do not have that possibility, unfortunately,
because of its use of RegisterServiceCtrlHandler() instead of
RegisterServiceCtrlHandlerEx(). I have items in QC to ask CodeGear to
change that, but they haven't acted on it yet. There are third-party
service frameworks that support HandlerEx() though, or you can write your
own service code from scratch instead.


Gambit


Remy Lebeau (TeamB)

unread,
Feb 1, 2008, 3:44:37 PM2/1/08
to

"AStringlist" <1737...@gmx.net> wrote in message
news:47a3...@newsgroups.borland.com...

> The reason why i'm looking for this is to make the service able
> to record the Logon/Logoffs off all users on my PC. For XP
> that works using "WTSRegisterSessionNotification". But
> unfortunately Windows 2000 Prof. doesn't know this api-function!

For systems prior to XP, one thing you can do is write and install a
replacement GINA DLL in order to track login/logout activity directly.
Another option is to have a non-service app start in the background whenever
a user logs in and have it detect the WM_ENDSESSION message. It can then
communicate those actions to the service.

> does anybody knows another way to detect Logon/Logoffs
> under Windows 2000 Prof.?

I suggest you go to http://www.deja.com and search the newsgroup archives.
That topic has been discussed many times before.


Gambit


AStringlist

unread,
Feb 2, 2008, 4:39:18 AM2/2/08
to
thx (and all other replyers too),

i just tried to check it out with these "RegisterServiceCtrlHandlerEx". But
my TurboDelphi does not know this function. Is there needed a special unit
for this?


AStringlist

unread,
Feb 2, 2008, 8:21:42 AM2/2/08
to
ok, now i check it out only with the "RegisterServiceCtrlHandler"-function
...and for this the WinSvc-Unit is sufficent. "RegisterServiceCtrlHandlerEx"
is not necessary for me because its additional features are not useable in
W2k ...at least not in that parts which are interesting for me and my
momentary problem.


Remy Lebeau (TeamB)

unread,
Feb 4, 2008, 4:25:33 AM2/4/08
to

"AStringlist" <1737...@gmx.net> wrote in message
news:47a46e84$1...@newsgroups.borland.com...

> ok, now i check it out only with the "RegisterServiceCtrlHandler"-function
> ...and for this the WinSvc-Unit is sufficent.
> "RegisterServiceCtrlHandlerEx" is not necessary for me

Yes, it is. As I explained to you earlier, RegisterServiceCtrlHandlerEx()
is requird in order for a service to receive SERVICE_CONTROL_SESSIONCHANGE
notiications. RegisterServiceCtrlHandler(), which TService uses, cannot do
that.


Gambit


0 new messages