473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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

Apr 25 '06 #1
4 5337
gw*****@kc.rr.com wrote:
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
Apr 25 '06 #2
On 24 Apr 2006 18:43:47 -0700, gw*****@kc.rr.com wrote:
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.Bound s
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
Apr 25 '06 #3
GWhite,

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

Cor

<gw*****@kc.rr.com> schreef in bericht
news:11*********************@v46g2000cwv.googlegro ups.com...
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

Apr 25 '06 #4
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...

--
Patrice

<gw*****@kc.rr.com> a écrit dans le message de news:
11*********************@v46g2000cwv.googlegroups.c om...
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

Apr 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sambucus | last post by:
Hi all!. I'm trying to capture a screen shot of a window. This works good until the window is partly or completley hidden, then i get the graphics of what is visible on my screen (the windows...
4
by: Madestro | last post by:
Hi guys, I have a little problem. I have a class that uses Windows API to capture a snapshot of the screen. I have this class in a library that I include in my projects. When I try to use...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
1
by: hanson | last post by:
How can i create the function of ScreenCapture in the windows service?????
1
by: hemant | last post by:
I am trying to Caputre the screen in windows service with the GDI Api of Win32 in vb.net 1. CreateDc 2. CreateCompatibleDC 3. CreateCompatibleBitmapDc 4. Bitblt 5. SelectObject 6. ...
4
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
I know how to capture a keypress for a windows application, but how would I go about doing it for a windows service? Rather than having a form in focus all the time, I would prefer to have...
3
by: =?Utf-8?B?Zmh1bnRlcg==?= | last post by:
I have a Windows Service that should pop a windows form right before logoff, for the user to enter some information. I got things working fairly well except that the user does not get to see the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.