Solved

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

Posted on 2008-10-18
8
960 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now