Event or callback when System's Desktop is changed

Event or callback when System's Desktop is changed

Post by hulkko12 » Fri, 10 Feb 2006 23:35:49


Hello,

Are there any Events or Callbacks that can inform Windows Service when
Windows OS is changing it's active Desktop?

For example in situation when Winlogon is executed and Windows OS is
starting to using Default Desktop (active Desktop changes from
"Winlogon" to "Default").

Any ideas how to get this information in Windows Service?

Cheers!
 
 
 

Event or callback when System's Desktop is changed

Post by Scherbina » Sat, 11 Feb 2006 00:31:05

Most likely you'll need to implement winlogon notification package that
tracks all "Logon" notifications and communicates with your service.

--
Vladimir

 
 
 

Event or callback when System's Desktop is changed

Post by Stefan Kuh » Sat, 11 Feb 2006 01:08:45

Hello



You can do a number of things, depending on which OS you target and
whether you want to rely on undocumented things. First, you could open
the named event "WinSta0_DesktopSwitch" with SYNCHRONIZE access (on
Session 0 in your service you have to prepend it with Global\). It gets
signalled each time a desktop change happens, but this is an
undocumented thing. On W2K, XP and W2K3 Server (but not on Vista and
Longhorn Server) you can implement a Winlogon Notification Package. On
XP, W2K3 Server, Vista and Longhorn Server you can handle the
SERVICE_CONTROL_SESSIONCHANGE control code in your service's HandlerEx
function.

HTH,


--
Stefan
 
 
 

Event or callback when System's Desktop is changed

Post by Kellie Fit » Sat, 11 Feb 2006 01:47:08

Hi,

Well, create a console process and wait until the control handler
receives the control signal CTRL_LOGOFF_EVENT, or the windows
message WM_USERCHANGED, if your process has a window, then:

Try to use a polling approach by using the API OpenInputDesktop(),
when this function starts failing, then the window station is in
the state of shutting down, and on its way to displaying the logIn
dialogBox, otherWise if the function starts succeeding again, then
you would receive a handle to the loggedOn user's deskTop.

OpenInputDesktop(0, FALSE, DESKTOP_ENUMERATE |
DESKTOP_READOBJECTS);

http://www.yqcomputer.com/

http://www.yqcomputer.com/

http://www.yqcomputer.com/

Hope these information helps,

Kellie.
 
 
 

Event or callback when System's Desktop is changed

Post by hulkko12 » Sat, 11 Feb 2006 03:06:53

Thanks a lot for you all!
 
 
 

Event or callback when System's Desktop is changed

Post by qfel » Sat, 11 Feb 2006 04:44:40

> whether you want to rely on undocumented things. First, you could open the
Wouldn't it break something?
An event can be manual or auto - reset.
First case does make sense only with PulseEvent. But, since it is unreliable
(kernel mode APC), would it be really used to signal desktop switch? Second
case would only release a single thread.
 
 
 

Event or callback when System's Desktop is changed

Post by Stefan Kuh » Sat, 11 Feb 2006 06:09:23

Hello qfel,



You are right in every aspect you describe. I and a few other folks have
made the observation that it works pretty reliably (I think I even got
the tip with this named event a few years ago from someone in this
newsgroup), just search deja for "WinSta0_DesktopSwitch". I would as
well suspect it works with PulseEvent. I don't think that this will
break something. After all, if this were the case, it would then first
and foremost be a security flaw of csrss: Should csrss allow ordinary
users access to a named object of its own with SYNCHRONIZE access which
would then break something critical?

BTW: I also never noticed that something broke by "subscribing" to this
event, although I do not say that this can never happen. This is the
very nature of something that is not documented.

For now, it works for me, but I know it can break with each patch for
csrss. But IIRC, this named event now exists at least since NT3.51 (I
definitely know it exists on NT4 Gold), so chances are, it continues to
exist because some MS apps need it. I would hope that Raymond Chen could
tell us one day what it is good for :-)

--
Stefan Kuhr
 
 
 

Event or callback when System's Desktop is changed

Post by Kellie Fit » Sat, 11 Feb 2006 06:45:35

Hi,

You can create a helper thread that has a message pump with
a window procedure to handle the windows message WM_USERCHANGED,
then have your helper application communicates with your service
process using an IPC mechanism, for example a named pipe.

Kellie.
 
 
 

Event or callback when System's Desktop is changed

Post by Stefan Kuh » Sat, 11 Feb 2006 07:18:47

Kellie,




Did you ever try this scheme or is this just speculation? My docs for
VC6 (MSDN Library July 2001) say about WM_USERCHANGED:

"Windows NT/2000 or later: Unsupported . "

Later MSDN version just state "Windows 95" as the minimal OS and do not
mention NT or its successors. I remember having done frustrating tests
with WM_USERCHANGED a number of years ago on NT4 until I disocvered the
little footnote I quoted above. And if I do a search on deja for
WM_USERCHANGED it is always you who advocates for WM_USERCHANGED and the
rest of the world doesn't seem to get WM_USERCHANGED working on
NT/W2K/XP. So does this really work for you or is this a holdover in
your memory from Windows 95 times?

--
Stefan
 
 
 

Event or callback when System's Desktop is changed

Post by Stefan Kuh » Sat, 11 Feb 2006 07:49:16

Kellie,



If this approach is done from a service, it will fail miserably in a TS
environment or XP FUS. If done from within the context of the
interactively logged on user, it will eat up CPU cycles in case the code
fails Paula Tomlinson's notepad-test from WDJ 03/1999 and will lead to
complicated synchronization issues if the user attempts to log off the
second time and an additional CTRL_LOGOFF_EVENT is received in a new
thread in the console mode process.

--
Stefan
 
 
 

Event or callback when System's Desktop is changed

Post by Kellie Fit » Sat, 11 Feb 2006 09:05:18

Hi Stefan,

The window procedure in my application handled the windows
message WM_USERCHANGED under Windows millennium, however, the
current help file on MSDN does not mention any limitations for
any version of Windows, it says the minimum operating systems
is Windows 95.

Kellie.
 
 
 

Event or callback when System's Desktop is changed

Post by qfel » Mon, 13 Feb 2006 01:29:03

I run a search on '_DesktopSwitch' text (windows and program files
directories), and have found only ctfmon.exe (which probably is used by MS
Office). I also did a test, 2 threads waiting on this event. Both awakened
(and event was reset then). So it seems PulseEvent is used, although I don't
know why they chose to use such unreliable notification (or maybe they just
know when kernel APC cannot be queued).