Solved

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

Posted on 2008-10-18
8
999 Views
Last Modified: 2013-12-04
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
0
Comment
Question by:Valty
  • 4
  • 4
8 Comments
 
LVL 6

Accepted Solution

by:
ChristianWimmer earned 500 total points
ID: 22748094
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
 

Author Comment

by:Valty
ID: 22748235
>>> 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
 
LVL 6

Assisted Solution

by:ChristianWimmer
ChristianWimmer earned 500 total points
ID: 22748460
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:Valty
ID: 22748491
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
 
LVL 6

Assisted Solution

by:ChristianWimmer
ChristianWimmer earned 500 total points
ID: 22748926
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
 
LVL 6

Expert Comment

by:ChristianWimmer
ID: 22748930
I just forget to mention this simple class for pipes:
http://www.codeproject.com/KB/IP/cnamedpipe.aspx
0
 

Author Comment

by:Valty
ID: 22749118
Thank you very much ;-)
0
 

Author Closing Comment

by:Valty
ID: 31507411
Thank you ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question