Windows / Problem to make a screenshot via a Local interactive Service

First, hello all !

I need for my application to make screenshots by a local service.

But as you know, in Windows Vista, the window station 0 (services) is isolated from user windows stations.

As soon as I realize a screenshot directly from the service, I get a black image because winsta0 has no interactive desktop

Then, I have two choices:

- My service is launching a program that captures screen, via CreateProcessAsUser. But this solution is bad in my opinion: I must record my image on the disk and read it via the service.

- The second option would be to recover the window station for the current user, and then retrieve his desktop and then make the screenshot.

The problem is that MSDN do not document that correctly.

I do not know how to retrieve the window station of the current user (via the process explorer.exe ???), and how to retrieve the user's desktop to use SetProcessWindowStation and SetThreadDesktop.

Is this second solution is feasible? Or is there process easier?

I do not quite understand the mechanisms of Windows Vista about window stations and desktop.

Sorry for my awful english.

I really need help, thanks in advance to answer me !


PS: I have founded this url's, but the codes always using winsta0/default (probably because Vista was not released when the codes where created)

http://www.derkeiler.com/Newsgroups/microsoft.public.platformsdk.security/2003-09/0234.html
http://www.cs.helsinki.fi/u/mlaanti/InteractiveService.txt
ValtyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChristianWimmerCommented:
Your first solution is the only correct solution that is officially available. Your service runs in a different session (=0) than any logged on user and each session has its own window station and set of desktops. However the WindowsAPI denies access to window stations and desktops in another session (unless you're using a driver). So there is no way to get a desktop in another session directly.
The only way is to run a separate program in the user's session and to make the screenshot. There are several other solutions beside saving the image into a file:
* Pipe
* Shared Memory
* TCP/UDP

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ValtyAuthor Commented:
>>> However the WindowsAPI denies access to window stations and desktops in another session (unless you're using a driver)

Do you want to say that SetProcessWindowStation can't work in a SYSTEM service (in the case I have the active window station) ?
0
ChristianWimmerCommented:
No, SetProcessWindowStation also works for SYSTEM but only  for window stations in the same session. You cannot get a handle to a window  station of another session : OpenWindowStation only accepts window station names of the session of the application.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

ValtyAuthor Commented:
Okay, thank you very much for this fast and precise answer !

A last question :

In your opinion, what should I use to "transfer" my data between the program runned by the service "AsUser" and the service ?

Pipe ? Shared memory ?

I'm not familiar at all with this concepts...

Note that I will tranfer images (screen captures) and text-based data (keyboard hook, for example)

I would be very grateful if you had some examples !
0
ChristianWimmerCommented:
Pipes are uni- or bi-directional communcation channels for inter process communication.
To use them across sessions, you need to adapt the server's (on service side) security descriptor as described here
http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_22961758.html?sfQueryTermInfo=1+c+pipe
This also applies to shared memory.
How communication is started you can read here:
http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_10080946.html?sfQueryTermInfo=1+c+pipe
http://www.experts-exchange.com/Programming/Languages/C/Q_20780678.html?sfQueryTermInfo=1+c+pipe
http://www.experts-exchange.com/Programming/Languages/Java/Q_21437476.html?sfQueryTermInfo=1+c+pipe

Also checkout this simple app using pipes:
http://www.codeproject.com/KB/cpp/loggerservice.aspx

It is mandatory that you'll use named pipes because handles cannot be send across session boundaries.

0
ChristianWimmerCommented:
I just forget to mention this simple class for pipes:
http://www.codeproject.com/KB/IP/cnamedpipe.aspx
0
ValtyAuthor Commented:
Thank you very much ;-)
0
ValtyAuthor Commented:
Thank you ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.