A few weeks ago, i posted a few guidelines on how Services running in Session 0 under Windows Vista can create applications in interactive user sessions. I also had the chance to present the same at a couple of developer sessions here in India. I have received a lot of feedback on the guidelines that i mentioned earlier. This post is an attempt to clean up the confusion and clarify the rudimentaries in detail.

1) If you already have a Service application running on pre-XP Operating Systems (Windows 2000 etc) you may choose to follow the guidelines from my earlier post.  Please note, however, that while doing so will only make your service compatible with Vista; but it is not the best way to do so. Some of the issues your service might run into include Fast User Switching scenarios (FUS is enabled in Vista, even for domain-joined computers), obtaining the interactive user token etc.

2) If you are looking to write great applications for Windows Vista and if you must write services, then the best way to do it is as:

 a) First call WTSEnumerateSessions to obtain a list and count of all the Terminal Services Sessions on your local machine or the machine where the service is intended to run.

b) From the list of Terminal Services Sessions, determine the one which is currently Active. A Session that is active, will have its State set as WTSActive.

c) For the active session, get the SessionId.

d) Using the SessionId obtained above, make a call to WTSQueryUserToken to obtain a valid user token for that session.

e) Use the token obtained to make a call to CreateProcessAsUser.

This posting is provided "AS IS" with no warranties, and confers no rights. The Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm