Any 'Windows Service' Experts? Why can't I capture the screen??

G

gwhite1

I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function
 
C

Chris

I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

The windows service runs in it's own session. This is why you can't
make an interactive service and you can't screen capture.

Chris
 
G

gene kelley

I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function


I'm not sure if this is related, but:
With Windows Media Player ver 9 and earlier, you use to be able to
screen capture a running video via the PrintScreen key and the frame
that was playing at the time would show in the resulting capture. With
ver 10 (and possibly from an additional XP upgrade), you no longer can
capture the frame. All you get is a blank media player. Screen capture
of a running video on any other player that I have, here, works as
expected.

I don't recall what MS calls it, but I believe it has something to do
with their attempt to protect media licensing rights.

Gene
 
C

Cor Ligthert [MVP]

GWhite,

A service cannot reach (direct) the screen. (I never tried it, therefore it
was to often written here).

Cor
 
P

Patrice

Try perhaps to check the "allow service to interact with desktop" checkbox.

A service is generally not tied to the desktop. It runs in its own
context...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top