Re: Windows Service - Fast User Switching - Find Active Desktop Problem
From: Eduardo Francos (efrancos_at_wanadoo.fr)
Date: 04/19/05
- Previous message: Peter Boulton: "Given: Service+named pipe from client. Wanted:Launch process on currently active user's desktop"
- In reply to: Peter Boulton: "Re: Windows Service - Fast User Switching - Find Active Desktop Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 19 Apr 2005 10:47:50 +0200
Peter Boulton wrote:
> Eduardo Francos wrote on 18/04/2005 07:12:
>
>> Peter Boulton wrote:
>>
>>> Hi,
>>>
>>> I am writing a Windows Service, which is allowed to interact with the
>>> desktop. (I realise that this is not recommended, but it is
>>> currently a constraint.) It needs to post advice windows on the
>>> desktop of whoever is logged in. With fast user switching this could
>>> be any one of any number of concurrent sessions. My service needs to
>>> post the windows to the active session, so that the active user can
>>> interact with it.
>
>
> <snipped>
>
>>
>>
>> AFAIK services are always run in the console terminal session, Session
>> 0. Addressing WinSta0 from a service will then always point to that
>> session.
>>
>> Running a program within the security context of the user can be done
>> simple by adding a UI client program in the Run key of HKLM or HKCU,
>> then use whatever IPC scheme that suits your needs to communicate with
>> the service.
>> You may use the WTSRegisterSessionNotification related API group to
>> know when user sessions are activated/deactivated so the service knows
>> which client to notify. Alternatively the service can notify all
>> connected clients and have the client UI decide whether to interact
>> with its user or not.
>>
>> For further information you can refer to "How To Design a Service to
>> Interact with Multiple User Sessions"
>> http://support.microsoft.com/default.aspx?scid=kb;en-us;308403
>>
>> or "Fast User Switching: Issues for Assistive Technology Vendors"
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/accessibility.asp
>>
>>
>>
>>
>> Eduardo
>
>
>
> Thanks for the reply. So, are you saying what I want to do is
> impossible? That is, launch a process in the currently logged on user's
> context from my service, on the desktop of whoever has sent the ipc via
> a named pipe to my service?
>
> If so, how do I get this, given the named pipe handle from the calling
> process?
>
> Please be gentle with me - this stuff is very new to me! Code example
> would be very much appreciated!
>
> Thanks.
>
> Pete
No, I'm not saying it's impossible, only that the approach may be harder
to implement due to the constrains on services.
Concerning the communication between the client (running in a user
session) and the service I'm quoting from the first article reference I
gave you on my previous posting
(http://support.microsoft.com/default.aspx?scid=kb;en-us;308403)
=======================
The server process (your service) then communicates with the appropriate
client through some means of interprocess communication to tell the
client when to display the GUI. The client, in turn, communicates the
results of the user's interaction back to the service so that the
service can act appropriately.
Because there will be multiple clients running on the system (a separate
client running in each user session), the service must have a
well-defined method to distinguish the clients. The most common method
to distinguish clients is to name the channel of communication by using
the client's session ID.
For example, if the client is running in session 4, the client may
create a pipe whose name is a concatenation of an unpublished GUID,
followed by "Channel_4". The client will then pass its session ID to the
service (perhaps by connecting to another pipe that is created by the
service) so that the service knows to connect to the "Channel_4" pipe.
The client can obtain its session ID by calling
WTSQuerySessionInformation() with WTSSessionId as the information class.
=======================
For code examples on how to use named pipes you can refer to the MSDN
article "Named Pipe Instances" at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/named_pipe_instances.asp
Eduardo
- Previous message: Peter Boulton: "Given: Service+named pipe from client. Wanted:Launch process on currently active user's desktop"
- In reply to: Peter Boulton: "Re: Windows Service - Fast User Switching - Find Active Desktop Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|