?
Solved

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

Posted on 2008-10-18
8
Medium Priority
?
1,083 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 2000 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 2000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 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