Solved

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

Posted on 2008-10-18
8
1,024 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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