4

I've got DirectShow based screen capture software. Internally it calls CopyScreenToBitmap function to grab screen. Then the picture is compressed by ffdshow. It works fine as a desktop application, but as window service, on certain computers it does not work (black picture). I've set 'Allow service to interact with desktop' and run that service on current user account. Any ideas what could be wrong?

I test it on windows XP, but it is expected to work on Vista and 7 as well.

Yes it works as desktop application on all computers, but on some of them (on majority of them) it fails as a service.

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Roman Motyka
  • 649
  • 1
  • 6
  • 15
  • What operating systems is running on the computers on which your service fails to operate properly? – Mihai Limbășan Jun 16 '09 at 15:10
  • @bezieur: "It is expected to work" != "will work", or even "has a remote chance of working". You shouldn't operate with "it is expected to work", you should test it. The Win32 service model has changed significantly in Vista and up. – Mihai Limbășan Jun 16 '09 at 15:51
  • @Mihai: Sure, you are right! I just meant that it must work on XP at the moment, but in a future (a short one) the requirements will be to work on newer ms os systems :-). – Roman Motyka Jun 18 '09 at 09:39
  • @bezieur: The current incarnation is much better phrased, thanks :) – Mihai Limbășan Jun 18 '09 at 12:55
  • from http://stackoverflow.com/questions/1832384/c-capture-screen-from-windows-service it appears that Vista doesn't "allow service to interact with desktop" – rogerdpack Sep 26 '12 at 16:21
  • see also: http://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop-session/12851218 – Theraot Mar 24 '13 at 07:41

2 Answers2

4

As I understand it, a change was made in Vista that moved services onto a separate desktop from the console user. While you have ticked the box that "allows access" to the desktop, I think you still have to pragmatically switch your service to use that desktop.

Here is a blog post with some useful info and examples.

Jon Grant
  • 11,369
  • 2
  • 37
  • 58
4

Try this in addition to allowing access to the desktop:

  1. Enumerate all Window Stations: EnumWindowStations
  2. Find the window station for the logged on user, and make it your process' window station: SetProcessWindowStation - see example in this thread
  3. Then set the desktop for your current thread to the default desktop of the window station also here
  4. Then get the DC of the desktop using one of a few methods, including

    CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL)

    Good luck

Mike Marshall
  • 7,788
  • 4
  • 39
  • 63
  • That's the point! Thank all of you for a help. Additionally I've found the article: http://www.codeproject.com/KB/system/SystemTrayIconInSvc.aspx which covers that issue as well. – Roman Motyka Jun 18 '09 at 09:34
  • I am using this for my website for [Teen Patti Game](https://paisabhai.in/teen-patti-game) . and its working like charm. Thanks! – Manisha Apr 12 '23 at 15:17