๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12868

Re: Application notification on Machine restart or shutdown

#12868
From: Remy Lebeau (TeamB)
Date: Tue, 11 Nov 2003 21:52
38 lines
2774 bytes
"Conny H๏ฟฝkansson" <conny@allimac.se> wrote in message
news:3fb15541@newsgroups.borland.com...

> Now that i know that this is a teadious task to accomplish I
> want to know what messages to look for when using a
> traditional application that is started when a user is login in
> to the computer, and when he is login out.

Under WinXP and 20003 only, you can use WTSRegisterSessionNotification() to
request the WM_WTSSESSION_CHANGE messages be sent to your app.  This is not
available on any of the other Windows OSs.  For those, there are no messages
for login, and for logout you can simply catch the WM_QUERYENDSESSION or
WM_ENDSESSION message, which will tell you whether it is a logout or a
shutdown.

> Do I need to setup a system wide hook with the SetWindowsHookEx
> function, which demands a DLL file to store the callback procedure
> or is there a much simpler method to do this?

No, you do not need a global hook at all.  For a normal app, just intercept
the desired messages in your form's WndProc() method, or alternatively use
the TApplication::HookMainWindow() method to hook the hidden TApplication
window (some messages may go there instead of to any of your forms).

> I want some work to be processed when the user is login in,
> aswell as when he logout's.

In order to detect a login, your app must be executing as a service to begin
with so that it is running before the login occurs.  For a normal app, that
requires registering the app under the "RunServices" key in the Registry,
and for the app to call RegisterServiceProcess() when it first starts up and
also when it is being terminated.  That will also allow the app to survive a
logout (which normally shuts down all non-service apps) by intercepting and
ignoring WM_ENDSESSION from killing the app.


Gambit
Technical Details
Message-ID: <3fb15956$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3fb15541@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10cc67,c54773486c2a14af
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-11 14:09:51 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3fb15541@newsgroups.borland.com>
Subject: Re: Application notification on Machine restart or shutdown
Date: Tue, 11 Nov 2003 13:52:34 -0800
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.137.149
Message-ID: <3fb15956$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1068587350 67.22.137.149 (11 Nov 2003 13:49:10 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail